public with sharing class InquiryPredictsDateChangeHandler extends Oly_TriggerHandler{ private List oldList; private List newList; private Map oldMap; private Map newMap; public InquiryPredictsDateChangeHandler() { this.oldList = (List) Trigger.old; this.newList = (List) Trigger.new; this.oldMap = (Map) Trigger.oldMap; this.newMap = (Map) Trigger.newMap; } protected override void afterUpdate() { addColumn(); } //当审批流程走完时 更新 询价相关字段 private void addColumn(){ //DB202309348278 询价页面新增字段需求 流失数 20230927 lt start //本财年 Date monyear; Date today = Date.today(); Integer month = today.month(); if(month <= 3){ monyear = Date.newInstance(today.year(), 4, 1); }else{ monyear = Date.newInstance(today.year()+1, 4, 1); } System.debug('test20230927---monyear:'+monyear); //DB202309348278 询价页面新增字段需求 流失数 20230927 lt end List oppList = new List(); Map oppMap = new Map(); List oppIdList = new List(); for (InquiryPredictsDateChange__c ipd :newList ) { //判断更新前后的状态是否不同 若不同,则判断更新后的状态是否为'已批准' if ((ipd.Predicted_Date_Status__c != oldMap.get(ipd.Id).Predicted_Date_Status__c) && ipd.Predicted_Date_Status__c == '已批准' ) { String oppId = ipd.Opportunity__c ; Opportunity opp = new Opportunity(); opp.Id = oppId; // opp.Close_Forecasted_Assume_Date__c = ipd.Close_Forecasted_Assume_Date__c; //担当日 opp.Close_Forecasted_Date__c = ipd.Close_Forecasted_Date__c; //KPI日 opp.CloseDate = ipd.CloseDate__c; //结束日期/预测发货日 opp.Date_InAdvance_Delay__c = ipd.Date_InAdvance_Delay__c; //日期提前/延后 opp.Predicted_date_ChangeReason__c = ipd.Predicted_date_ChangeReason__c; //改变预测日期原因 // opp.Opp_New_Mark__c = ipd.Opp_New_Mark__c; //询价新建标记 opp.Opp_Delay_Mark__c = ipd.Opp_Delay_Mark__c; //询价延后标价 opp.ForecastApprovalTime__c = Datetime.now(); //DB202309348278 询价页面新增字段需求 流失数 20230927 lt start //流失数:预测订货日修改到本期后。 System.debug('test20230927---opp.Close_Forecasted_Date__c:'+opp.Close_Forecasted_Date__c); if(opp.Close_Forecasted_Date__c >= monyear){ opp.LostCntNum__c = 1; }else{ opp.LostCntNum__c = 0; } //DB202309348278 询价页面新增字段需求 流失数 20230927 lt end oppList.add(opp); } } if (oppList.size() > 0) { System.debug('lt123oppList'+oppList); update oppList; } } }