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

Updating a record from a trigger on another record
If I want to have a trigger on a record in one object, that updates a record in another object, how can I accomplish this without having a SOQL query inside a for loop? We are going to want to map a couple fields back to the other record, so I'm not sure the most efficient way to do this. I was thinking something like this:
trigger ContactUpdater on Custom_Object_Name__c (after update) { List<Contact> Contactlist = new List<Contact>(); List<Contact> updatedContacts = new List<Contact>(); for(Custom_Object_Name__c p : trigger.new){ If(p.Associated_Contact__c != Null){ Contactlist.add(p.Associated_Contact__c); } for(Contact c : [SELECT Id FROM Contact WHERE Id IN :Contactlist]){ c.FieldToUpdate = p.FieldValue; updatedContacts.add(c); } update updatedContacts; }
Is there anything inherently wrong with how this is coded?
try this.
What would be the difference between doing that, and doing something like this: