public without sharing class ProductScoreTableHistoryHandler extends Oly_TriggerHandler { private Map newMap; private Map oldMap; private List newList; private List oldList; public ProductScoreTableHistoryHandler() { this.newMap = (Map) Trigger.newMap; this.oldMap = (Map) Trigger.oldMap; this.newList = (List) Trigger.new; this.oldList = (List) Trigger.old; } protected override void beforeInsert() { setproduct_CategoryPriceInfo(); } protected override void beforeUpdate() { //setproduct_CategoryPriceInfo(); } private void setproduct_CategoryPriceInfo() { Id PSTH_RecordTypeId = Schema.SObjectType.Product_Score_Table_History__c.getRecordTypeInfosByDeveloperName().get('TargetPDCA').getRecordTypeId(); //产品分类价格表 List pstIdList = new List(); for (Product_Score_Table_History__c psth : newList) { if (psth.RecordTypeId == PSTH_RecordTypeId && String.isNotBlank(psth.UniqueKey__c)) { pstIdList.add(psth.UniqueKey__c.split(':')[1] + ':' + psth.Category3__c +':'+ psth.Category4__c); } } Map pstIdMap = new Map(); for(Product_CategoryPrice_Table__c tmpObj : [SELECT Id, UniqueKey__c FROM Product_CategoryPrice_Table__c WHERE UniqueKey__c IN :pstIdList]){ pstIdMap.put(tmpObj.UniqueKey__c, tmpObj); } for (Product_Score_Table_History__c psth : newList) { if (psth.RecordTypeId == PSTH_RecordTypeId && String.isNotBlank(psth.UniqueKey__c)) { String pstUniqueKey = psth.UniqueKey__c.split(':')[1] + ':' + psth.Category3__c +':'+ psth.Category4__c; if (pstIdMap.containsKey(pstUniqueKey)) { psth.Product_CategoryPrice_Table__c = pstIdMap.get(pstUniqueKey).Id; } } } } }