You need to sign in to do that
Don't have an account?
mng0827
System.ListException: Duplicate id in list
Hi,
I keep getting this error on one my triggers:
"System.ListException: Duplicate id in list:..."
I'm not sure where the issue is but below is the trigger:
trigger updateContactExactTarget on xtma_Individual_Email_Result__c (after insert) {
List <String> Code = new List <String> ();
for (Integer i = 0; i < Trigger.new.size(); i++) {
if(Trigger.new[i].Report_Name__c != null && Trigger.new[i].Contact__c != null) {
Code.add(Trigger.new[i].Code2__c); // List of the codes
}
}
// get all the ContactExactTarget which have the same code as the code of IndividualEmailResult
List <ContactExactTarget__c> CodeList = new List <ContactExactTarget__c> ([Select Id, Name, Code__c, Individual_Email_Result2__c from ContactExactTarget__c where Code__c in :Code and Individual_Email_Result2__c = null]);
List <ContactExactTarget__c> CETsToUpdate = new List <ContactExactTarget__c>();
for(ContactExactTarget__c c : codeList) {
for (Integer i = 0; i < Trigger.new.size(); i++) {
if (c.code__c == Trigger.new[i].Code2__c) {
c.Individual_Email_Result2__c = Trigger.new[i].Id; // Populating the Individual Email Result field
CETsToUpdate.add(c);
}
}
}
if(CETsToUpdate != null || CETsToUpdate.size() >0)
update CETsToUpdate; // Update the list of ContactExactTarget
}
Can someone help me fix this trigger?
I keep getting this error on one my triggers:
"System.ListException: Duplicate id in list:..."
I'm not sure where the issue is but below is the trigger:
trigger updateContactExactTarget on xtma_Individual_Email_Result__c (after insert) {
List <String> Code = new List <String> ();
for (Integer i = 0; i < Trigger.new.size(); i++) {
if(Trigger.new[i].Report_Name__c != null && Trigger.new[i].Contact__c != null) {
Code.add(Trigger.new[i].Code2__c); // List of the codes
}
}
// get all the ContactExactTarget which have the same code as the code of IndividualEmailResult
List <ContactExactTarget__c> CodeList = new List <ContactExactTarget__c> ([Select Id, Name, Code__c, Individual_Email_Result2__c from ContactExactTarget__c where Code__c in :Code and Individual_Email_Result2__c = null]);
List <ContactExactTarget__c> CETsToUpdate = new List <ContactExactTarget__c>();
for(ContactExactTarget__c c : codeList) {
for (Integer i = 0; i < Trigger.new.size(); i++) {
if (c.code__c == Trigger.new[i].Code2__c) {
c.Individual_Email_Result2__c = Trigger.new[i].Id; // Populating the Individual Email Result field
CETsToUpdate.add(c);
}
}
}
if(CETsToUpdate != null || CETsToUpdate.size() >0)
update CETsToUpdate; // Update the list of ContactExactTarget
}
Can someone help me fix this trigger?
before doing DML operation. Please fire a loop on CETsToUpdate to create a Map<Id,ContactExactTarget__c> MapConExact so there will not be duplicate Ids
and do DML operation on
update MapConExact.Values();