/** * 20220210 lt UpdateIdentification()--更新产品上的“预留产品”标识 * 预留产品对象会关联一个产品主数据 * 创建预留产品时,将产品主数据上的“预留产品”标识 更新为 true */ public without sharing class LastbuyProductHandler extends Oly_TriggerHandler { private Map newMap; private Map oldMap; private List newList; private List oldList; public LastbuyProductHandler() { this.newMap = (Map) Trigger.newMap; this.oldMap = (Map) Trigger.oldMap; this.newList = (List) Trigger.new; this.oldList = (List) Trigger.old; } protected override void beforeInsert(){ } protected override void afterInsert(){ UpdateIdentification(); } //更新标识 private void UpdateIdentification(){ //存产品的ID List pList = new List(); for(LastbuyProduct__c lbp : newList){ if(lbp.ProductName__c != null){ pList.add(lbp.ProductName__c); } } List proList = [select id, LastbuyProductFLG__c from Product2 where Id in :pList]; List pflgList = new List(); for(Product2 lbp : proList){ if(lbp.LastbuyProductFLG__c == false){ lbp.LastbuyProductFLG__c = true; pflgList.add(lbp); } } if(pflgList.size() > 0){ update pflgList; } } }