public with sharing class OpportunityFileTriggerHandler extends Oly_TriggerHandler { //CHAN-BCNCRB XHL private Map newMap; private Map oldMap; private List newList; private List oldList; public OpportunityFileTriggerHandler() { 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(); } protected override void beforeDelete(){ beforeDeleteSetValue(); } //CHAN-BER3N8; 一个询价只能有一个类型为"G.T1清单"的询价文件 private void beforeInsertValue(){ List oppIds = new List(); List opportunityFiles = new List(); for( Opportunity_File__c ofc :newList ){ if ( ofc.Oppor_File_Stage__c == 'G' ) { oppIds.add(ofc.Opportunity__c); opportunityFiles.add(ofc); } } List opportunity_FileS = [select Id,Oppor_File_Stage__c,Opportunity__c, Opportunity__r.Opportunity_No__c from Opportunity_File__c where Opportunity__c In :oppIds And Oppor_File_Stage__c = 'G']; if ( opportunity_FileS.size() > 0) { for (Opportunity_File__c ofc : opportunityFiles) { ofc.addError('该询价已含有类型为G.T1清单的询价文件,不可重复创建 '); continue; } } } //CHAN-BER3N8; 询价做win之后,不可删除类型为"G.T1清单"的询价文件 private void beforeDeleteSetValue () { List oppIds = new List(); List opportunity_FileS = new List(); List idNowList = new List(); List opportunitys = new List(); for( Opportunity_File__c ofc :oldList ){ if ( ofc.Oppor_File_Stage__c == 'G' && ofc.If_Opportunity_win__c == true){ ofc.addError('询价已SAP上传(WIN),不能删除该询价文件'); continue; } else if (ofc.Oppor_File_Stage__c == 'G'){ oppIds.add(ofc.Opportunity__c); idNowList.add(ofc.Id); } } if (oppIds.size() > 0) { opportunity_FileS = [select Id,Oppor_File_Stage__c,Opportunity__c from Opportunity_File__c where Opportunity__c In :oppIds And Id not In :idNowList And Oppor_File_Stage__c = 'G']; if (opportunity_FileS.size() <= 0) { for (String oppId : oppIds ) { Opportunity opp = new Opportunity(); opp.Id = oppId; opp.If_UploadT1Detailed__c = false; opportunitys.add(opp); } } if (opportunitys.size() > 0) { update opportunitys; } } } //询价win之后,不可修改类型"G.T1清单"的询价文件 private void beforeSetValue() { List oppIds = new List(); List opportunitys = new List(); for( Opportunity_File__c ofc :newList ){ //CHAN-BER3N8;Start if (ofc.Oppor_File_Stage__c == 'G' && ofc.If_Opportunity_win__c == true) { ofc.addError('询价已SAP上传(WIN),不能修改该询价文件'); continue; } //CHAN-BER3N8;End if (ofc.Oppor_File_Stage__c == 'G' && ofc.Last_upload_time__c != null) { oppIds.add(ofc.Opportunity__c); } } if (oppIds.size() > 0) { for (String oppId : oppIds ) { Opportunity opp = new Opportunity(); opp.Id = oppId; opp.If_UploadT1Detailed__c = true; opportunitys.add(opp); } } if (opportunitys.size() > 0) { update opportunitys; } } }