Hoping someone can help me fix this. I understand that this error is because I'm trying to access a record that kicked off the trigger. I'm just not sure how to resolve it. Any help would be appreciated.

trigger EmailSummaryCreate on wbsendit__Campaign_Activity__c (after insert, after update) {

//List of summary records that needs to be created 
List<CMRules__Email_Tracking_Summary__c> SummaryToInsert = new 

//    set for only the campaign names in the current context
set<string> uKeyHistory = new set<string>();
for(wbsendit__Campaign_Activity__c hKey : trigger.new){
   if(hKey.CMRules__Unique_Key__c != null){

 Map<String,CMRules__Email_Tracking_Summary__c> matchingHistMap = new 
 for(CMRules__Email_Tracking_Summary__c sum : [SELECT Id, 
 FROM CMRules__Email_Tracking_Summary__c 
 where CMRules__Unique_Key__c IN :uKeyHistory]){
   matchingHistMap.put(sum.CMRules__Unique_Key__c, sum);

List<wbsendit__Campaign_Activity__c> historyFieldtoUpdate = new List<wbsendit__Campaign_Activity__c>();

// map of existing summaries records
 Map<string, Id> uKey = new Map<string, Id>();
 for(CMRules__Email_Tracking_Summary__c u : [SELECT Id, 
 FROM CMRules__Email_Tracking_Summary__c 
 where CMRules__Unique_Key__c IN :uKeyHistory]){
   uKey.put(u.CMRules__Unique_Key__c, u.Id); 

 for(wbsendit__Campaign_Activity__c h : trigger.new){

   boolean      key1 = uKey.containsKey(h.CMRules__Unique_Key__c);
   list<string> key2 = uKey.values();
   //list<string> key4 = matchingHistMap.values();
   list<string> key3 = h.CMRules__Unique_Key__c.split(':', 0);


 h.CMRules__Email_Tracking_Summary__c = matchingHistMap.get(h.CMRules__Unique_Key__c).Id;


       }else {             
           //create new summary record
           CMRules__Email_Tracking_Summary__c s = new CMRules__Email_Tracking_Summary__c();              
           s.CMRules__Campaign_Name__c = h.name;
           s.CMRules__Contact__c = h.wbsendit__Contact__c;

   insert SummaryToInsert;
   update historyFieldtoUpdate;

1 Answer 1


I was able to resolve this error by changing it to a before insert/update trigger, and removing the update DML since the before trigger.new takes care of the dml.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .