public without sharing class LostReportDetailHandler extends Oly_TriggerHandler { private Map newMap; private Map oldMap; private List newList; private List oldList; public LostReportDetailHandler() { this.newMap = (Map) Trigger.newMap; this.oldMap = (Map) Trigger.oldMap; this.newList = (List) Trigger.new; this.oldList = (List) Trigger.old; } protected override void beforeInsert() { beforeSetValue(); } protected override void afterUpdate() { checkDelete(); } protected override void afterDelete() { setDeleteField(); } private void beforeSetValue() { for (LostReport_Detail__c nObj : newList) { if (Trigger.isInsert && nObj.Asset_day__c == null) { nObj.Asset_day__c = nObj.Asset_day_F__c; } } } private void setDeleteField() { List ldList = new List(); List raesdList = new List(); for (LostReport_Detail__c oObj : oldList) { if (String.isNotBlank(oObj.Rental_Apply_Equipment_Set_Detail__c) && oObj.LostReport_Status_F__c != '草案中') { raesdList.add(new Rental_Apply_Equipment_Set_Detail__c(Id = oObj.Rental_Apply_Equipment_Set_Detail__c , DeleteLostReport_Detail_Reason__c = oObj.DeleteLostReport_Detail_Reason__c , HadLostReport_Detail__c = oObj.HadLostReport_Detail__c )); } if (String.isNotBlank(oObj.Inventory_Detail__c) && oObj.LostReport_Status_F__c != '草案中') { ldList.add(new Inventory_Detail__c(Id = oObj.Inventory_Detail__c , DeleteLostReport_Detail_Reason__c = oObj.DeleteLostReport_Detail_Reason__c , HadLostReport_Detail__c = oObj.HadLostReport_Detail__c )); } } if (ldList.size() > 0) { update ldList; } if (raesdList.size() > 0) { update raesdList; } } private void checkDelete() { List ldList = new List(); for (LostReport_Detail__c nObj : newList) { LostReport_Detail__c oObj = oldMap.get(nObj.Id); if (oObj.CancelLostReport__c != nObj.CancelLostReport__c && nObj.CancelLostReport__c) { ldList.add(new LostReport_Detail__c(Id = nObj.Id)); } } if (ldList.size() > 0) { delete ldList; } } }