You need to sign in to do that
Don't have an account?
Mark Liu
unhandled trigger caused by: System.ListException: Duplicate id in list: 001.............
Hey guys,
Was wondering if someone could help me out… I have built a trigger(below) to count the amount of contacts (that are marked as Primary Liaisons) in each account (of a certain account type) and this number is reported on a custom field that resides on each Account. However, whenever I use dataloader or any other CRM tools to mass update contacts, it gives me this error: “caused by: System.ListException: Duplicate id in list: 001……..” I believe it’s because many accounts of this specific record type have multiple contacts, therefore it was trying to update the same Account over and over again causing duplicate IDs?
Please let me know what I can do to resolve this duplicate ID issue. Help is much appreciated! :)
trigger primaryLiaisonCount2 on Contact(after update) {
LIST<account> accList = new List<account>();
set<String> allAccIds = new Set<String>();
for (Contact c1: trigger.new){
if (c1.Contact_ID_18_Characters__c != null){
allAccIds.add(c1.AccountID);} }
Decimal amount1=[SELECT count() FROM Contact WHERE AccountID IN :allAccIds AND Primary_Liaison__c != null AND Marketing_Status__c != 'Gone From Company' LIMIT 25];
LIST<account> acc1=[SELECT ID FROM Account WHERE ID IN :allAccIds AND recordtypeID ='012000000000j8S' LIMIT 25];
for (Contact c1: trigger.new){
for (Account acc2:acc1){
acc2.Primary_Liaisons__c = amount1;
accList.add(acc2);
}
}
Update accList;
}
Was wondering if someone could help me out… I have built a trigger(below) to count the amount of contacts (that are marked as Primary Liaisons) in each account (of a certain account type) and this number is reported on a custom field that resides on each Account. However, whenever I use dataloader or any other CRM tools to mass update contacts, it gives me this error: “caused by: System.ListException: Duplicate id in list: 001……..” I believe it’s because many accounts of this specific record type have multiple contacts, therefore it was trying to update the same Account over and over again causing duplicate IDs?
Please let me know what I can do to resolve this duplicate ID issue. Help is much appreciated! :)
trigger primaryLiaisonCount2 on Contact(after update) {
LIST<account> accList = new List<account>();
set<String> allAccIds = new Set<String>();
for (Contact c1: trigger.new){
if (c1.Contact_ID_18_Characters__c != null){
allAccIds.add(c1.AccountID);} }
Decimal amount1=[SELECT count() FROM Contact WHERE AccountID IN :allAccIds AND Primary_Liaison__c != null AND Marketing_Status__c != 'Gone From Company' LIMIT 25];
LIST<account> acc1=[SELECT ID FROM Account WHERE ID IN :allAccIds AND recordtypeID ='012000000000j8S' LIMIT 25];
for (Contact c1: trigger.new){
for (Account acc2:acc1){
acc2.Primary_Liaisons__c = amount1;
accList.add(acc2);
}
}
Update accList;
}
Try the below code.
All Answers
Try the below code.