You need to sign in to do that
Don't have an account?

Duplicate Id in list-Even though code bulkified
Hello gurus,
I am trying to perform a mass update using the data loader,and the below code is throwing duplicate IDs error,
i know i am using SET ,but any pointers on using MAP so that i can fix the error.
All i am doing is copying 2 fields from child(appl__c) to parent(contact) where the parent is a lookup field in the child table.
Any pointers? thank you!
trigger abre on Appl__c (after insert, after update) {
Set<Contact> parents = new Set<Contact>();
for (Appl__c child : trigger.new) {
if(child.Id != null){
parents.add(new Contact(Id = child.Contact__c, Admit_Type__c = child.Admit_Type__c,Admit_Term__c=child.Admit_Term__c));
}
}
if(!parents.isEmpty()){
List<Contact> toUpdate = new List<Contact>();
toUpdate.addAll(parents);
update toUpdate;
}
}
I am trying to perform a mass update using the data loader,and the below code is throwing duplicate IDs error,
i know i am using SET ,but any pointers on using MAP so that i can fix the error.
All i am doing is copying 2 fields from child(appl__c) to parent(contact) where the parent is a lookup field in the child table.
Any pointers? thank you!
trigger abre on Appl__c (after insert, after update) {
Set<Contact> parents = new Set<Contact>();
for (Appl__c child : trigger.new) {
if(child.Id != null){
parents.add(new Contact(Id = child.Contact__c, Admit_Type__c = child.Admit_Type__c,Admit_Term__c=child.Admit_Term__c));
}
}
if(!parents.isEmpty()){
List<Contact> toUpdate = new List<Contact>();
toUpdate.addAll(parents);
update toUpdate;
}
}
Try following code
i am still testing this updated one,but wondering why the one i posted does not work for bulk updates?
thank you again!