public without sharing class AssetMaintainHeaderHandler extends Oly_TriggerHandler { private Map newMap; private Map oldMap; private List newList; private List oldList; public AssetMaintainHeaderHandler() { this.newMap = (Map) Trigger.newMap; this.oldMap = (Map) Trigger.oldMap; this.newList = (List) Trigger.new; this.oldList = (List) Trigger.old; } protected override void beforeUpdate() { beforeSetValue(); } protected override void beforeInsert() { beforeSetValue(); } protected override void afterUpdate() { afterSetValue(); } private void beforeSetValue(){ for (AssetMaintainHeader__c nObj : newList) { AssetMaintainHeader__c oObj; if (Trigger.isUpdate) { oObj = oldMap.get(nObj.Id); } if (Trigger.isInsert || (oObj != null && nObj.Status__c == '填写完毕' && nObj.Status__c != oObj.Status__c)) { nObj.Buzhang__c = nObj.Buzhang_ID_F__c; nObj.Zongjian__c = nObj.Zongjian_ID_F__c; } if(Trigger.isInsert){ if(nObj.MaintainType__c == '实物报废'){ nObj.RecordTypeId = [SELECT Id FROM RecordType WHERE DeveloperName = 'AssetMaintain_Scrapped'].Id; } else{ nObj.RecordTypeId = [SELECT Id FROM RecordType WHERE DeveloperName = 'AssetMaintain_NotScrapped'].Id; } } } } private void afterSetValue() { for (AssetMaintainHeader__c nObj : newList) { AssetMaintainHeader__c oObj = oldMap.get(nObj.Id); if(oObj.Status__c == '申请中' && nObj.Status__c == '已批准'){ AssetMaintainManualBatch amBatch = new AssetMaintainManualBatch(nObj.Id, true); Database.executeBatch(amBatch); } else if (oObj.Status__c == '申请中' && nObj.Status__c == '草案中'){ AssetMaintainManualBatch amBatch = new AssetMaintainManualBatch(nObj.Id, false, AssetMaintainManualBatch.Operation.UNFROZEN); Database.executeBatch(amBatch); } } } }