function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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;

}