You need to sign in to do that
Don't have an account?
MMA_FORCE
System.ListException: Duplicate id in list:??? Help in Trigger Please
Hi:
I am getting duplicate ID's in my trigger when really there are no dups in my list???
Where am I going wrong:
trigger updateSubjectArea on Subject_Area_RQ__c (after insert,after update) { List<Subject_Area__c> htoUpdte = new List<Subject_Area__c>(); Subject_Area__c sa; Set <ID> setOrderId = new set<ID>(); for (Subject_Area_RQ__c orderDetail :trigger.new) { setOrderId.add(orderDetail.Subject_Area__c); } List<Subject_Area__c> accounts = [SELECT Id FROM Subject_Area__c where Id IN :setOrderId]; for(Subject_Area_RQ__c sar : trigger.new){ for(Subject_Area__c a: accounts){ a.SARQ__c = sar.On_Track_Subject_Area__c; System.Debug('a.SARQ__c - ' +sar.On_Track_Subject_Area__c); htoUpdte.add(a); } update htoUpdte; } }
you don't have have to add the accounts to yet another list. Delete the htoUpdate.add(a) and update your list "accounts" instead.
All Answers
You add all of the records from the accounts list to htoUpdate for every record in the trigger, so if the trigger is for more than one record, then you'll have duplicates in the htpUpdate list.
you don't have have to add the accounts to yet another list. Delete the htoUpdate.add(a) and update your list "accounts" instead.
Thank you Both I decided to do the trigger this way: hmm Do you see any issues with this code?