You need to sign in to do that
Don't have an account?
RaviKumar
When an Insert/Update of a field in Contact Object that value needto be update in all remaining Contact records
When an Insert/Update of a field in Contact Object that value needto be update in all remaining Contact records
Below is the Trigger I've written.But when we update a record it throwsan ERROR :Duplicate Id's in List
trigger AccountFieldUpdate on Contact (after Update) {
List<Contact> C3_l = new List<Contact>();
for(Contact c1 : Trigger.new){
Account acc = [select id from Account where id =: c1.AccountId ];
List<Contact> c2_l = [Select name, AccountId, Department from
Contact where AccountId =: acc.id ];
for(Contact c2 : c2_l){
if(c1.id == c2.id){
}else{
c2.Department = c1.Department;
c3_l.add(c2);
}
}
}
update c3_l;
}
Below is the Trigger I've written.But when we update a record it throwsan ERROR :Duplicate Id's in List
trigger AccountFieldUpdate on Contact (after Update) {
List<Contact> C3_l = new List<Contact>();
for(Contact c1 : Trigger.new){
Account acc = [select id from Account where id =: c1.AccountId ];
List<Contact> c2_l = [Select name, AccountId, Department from
Contact where AccountId =: acc.id ];
for(Contact c2 : c2_l){
if(c1.id == c2.id){
}else{
c2.Department = c1.Department;
c3_l.add(c2);
}
}
}
update c3_l;
}
Anup Jadhav
That's because your update in the 'after update' trigger causes it to invoke the trigger again. Try adding this logic in a before update so you don't have to call update again.