+ Start a Discussion
jpwagnerjpwagner 

Trigger to update a different object on insert

I would've thought this would work...
 
trigger ContactLookupOnInsertTrigger on Contact (before insert) {
for (Contact c : Trigger.new){c.Account.SomeField = someValue;}}
 
But it doesn't.  Any thoughts/suggestions?
Thanks.
jpwagnerjpwagner
*bump*
 
in case the question is not clear...is it possible to update a field on another Object X through a trigger on Object Y   ???
 
Thanks.
jpwagnerjpwagner
In case anyone cared about this thread:
 
you have to create new instance of the object and declare that the id is equal to it...
 
 

trigger myTrigger on Contact (after insert) {

List<Account> accts = new Account[]{};

for (Contact c : Trigger.new) {

Account acct = new Account(id = c.AccountId, someField = c.someValue);

accts.add(acct);

}

update accts;

}