public with sharing class OpportunityFileOrderTriggerHandler extends Oly_TriggerHandler { private Map newMap; private Map oldMap; private List newList; private List oldList; public OpportunityFileOrderTriggerHandler() { this.newMap = (Map) Trigger.newMap; this.oldMap = (Map) Trigger.oldMap; this.newList = (List) Trigger.new; this.oldList = (List) Trigger.old; } protected override void beforeInsert(){ beforeInsertValue(); } protected override void beforeUpdate(){ beforeSetValue(); } private void beforeInsertValue(){ List statuIds = new List(); List statuOFiles = new List(); for( OpportunityFileOrder__c ofc :newList ){ if ( ofc.OpporFileStage__c == 'G' ) { statuIds.add(ofc.StatuAchievements__c); statuOFiles.add(ofc); } } if (statuIds.size() > 0) { List opportunity_FileS = [select Id,OpporFileStage__c,StatuAchievements__c from OpportunityFileOrder__c where StatuAchievements__c In :statuIds And OpporFileStage__c = 'G']; if (opportunity_FileS.size() > 0) { for (OpportunityFileOrder__c ofc : statuOFiles) { ofc.addError('该注残已含有类型为G.T1清单的询价文件,不可重复创建 '); continue; } } } } private void beforeSetValue() { List statuIds = new List(); Map statuIdMap = new Map(); List statuAList = new List(); for( OpportunityFileOrder__c ofo :newList ){ if (ofo.OpporFileStage__c == 'G' && ofo.LatestUploadTime__c != null) { statuIds.add(ofo.StatuAchievements__c); statuIdMap.put(ofo.StatuAchievements__c,true); } else if (ofo.OpporFileStage__c == 'G' && ofo.LatestUploadTime__c == null) { statuIdMap.put(ofo.StatuAchievements__c,false); } } if (statuIdMap.size() > 0) { for (String statuId : statuIdMap.keySet() ) { Statu_Achievements__c statuA = new Statu_Achievements__c(); statuA.Id = statuId; //statuA.If_UploadT1Detailed__c = true; statuA.If_UploadT1Detailed__c = statuIdMap.get(statuId); statuAList.add(statuA); } } if (statuAList.size() > 0) { update statuAList; } } }