public without sharing class TransferApplySummaryHandler extends Oly_TriggerHandler { private Map newMap; private Map oldMap; private List newList; private List oldList; private static Map raesdCMap = new Map(); public TransferApplySummaryHandler() { this.newMap = (Map) Trigger.newMap; this.oldMap = (Map) Trigger.oldMap; this.newList = (List) Trigger.new; this.oldList = (List) Trigger.old; } //20201109 ljh start protected override void beforeInsert() { beforeSetValue(); } //20201109 ljh add end protected override void beforeUpdate() { DateTime now = System.Now(); for (TransferApplySummary__c nObj : newList) { TransferApplySummary__c oObj = oldMap.get(nObj.Id); if (oObj.Cancel_Select__c == false && nObj.Cancel_Select__c == true) { nObj.Cancel_Mem__c = UserInfo.getUserId(); nObj.Cancel_Time__c = now; raesdCMap.put(nObj.Id, nObj); } } beforeSetValue();//20201109 ljh add } protected override void afterUpdate() { cancelDetail(raesdCMap, true); } //明細更新メソッド 更新明細:一覧Cancel明細もCancel // 一覧申请者收获NG明細更新Name // 必須項目:Cancel_Reason__c // @param raesdCMap Cancel一覧Map // @param allOrNone 不允许部分保存 // @return 保存结果 private static Database.SaveResult[] cancelDetail(Map raesdCMap, Boolean allOrNone) { // null.isEmpty の場合えラー if (raesdCMap == null) { raesdCMap = new Map(); } //更新明细 Map raesdMap = new Map(); //取消更新的明细 if (!raesdCMap.isEmpty()) { List raesds = [ Select Id, TransferApplySummary__c,TAESD_Status__c From TransferApplyDetail__c Where TransferApplySummary__c = :raesdCMap.keySet() AND Cancel_Select__c = false AND DeliverySlip__c = null]; for (TransferApplyDetail__c raesd :raesds) { raesd.Cancel_Select__c = true; //raesd.Cancel_Mem__c = UserInfo.getUserId(); //raesd.Cancel_Date__c = Date.today(); //raesd.Cancel_Time__c = System.now(); raesd.Cancel_Reason__c = raesdCMap.get(raesd.TransferApplySummary__c).Cancel_Reason__c; //raesd.Loaner_cancel_Remarks__c = raesdCMap.get(raesd.TransferApplySummary__c).Loaner_cancel_Remarks__c; raesdMap.put(raesd.Id, raesd); } } if (!raesdMap.isEmpty()) { return Database.update(raesdMap.values(), allOrNone); } return null; } //20201109 ljh add start private void beforeSetValue() { //20201109 ljh OCSM_BP5-44 调拨单设定对应_申请,一览,明细的命名规则 start for (TransferApplySummary__c nObj : newList) { if (nObj.First_TAD_Model_No_F__c != null && nObj.IndexFromUniqueKey__c != null) { nObj.Name = nobj.Name_F__c + ':'+nObj.First_TAD_Model_No_F__c+':'+ ((Integer) Math.round(nObj.IndexFromUniqueKey__c)).format().leftpad(3, '0'); //取消的时候名字加Canceled if (nObj.Cancel_Select__c) { nObj.Name += ':Canceled'; } } } //20201109 ljh OCSM_BP5-44 调拨单设定对应_申请,一览,明细的命名规则 end } //20201109 ljh add end }