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
mohammadd ismailmohammadd ismail 

Trigger from contact to account

As i am a newbie any help is appreciated on the below requirement.
How to write the trigger which converts the contact owner into account owner.Currenty we have a "TEST" user account in salesforce and anytime a contact is owned by this "TEST"user we want to change the contact owner to the account owner. Is this possible? any assistance would be appreciated.

Thanks.

 
Best Answer chosen by mohammadd ismail
NagendraNagendra (Salesforce Developers) 
Hi,


Try using Contains instead of Equals for the operator?  I'm not sure if Process Builder recognizes the 15 digit or 18 digit SFDC IDs.

Please mark this as the best solution if it helps.

Best Regards,
Nagendra.P

All Answers

Ankit SehgalAnkit Sehgal
trigger updateowner on Contact(after insert)
{
     Contact c=[SELECT OwnerId FROM Contact WHERE Id IN: Trigger.new LIMIT 1];
     Account a=[SELECT OwnerId,Name FROM Account WHERE Id=:c.AccountId];
     c.OwnerId=a.OwnerId;
     update c;
}

Give this a try :p
NagendraNagendra (Salesforce Developers) 
Hi,


Try using Contains instead of Equals for the operator?  I'm not sure if Process Builder recognizes the 15 digit or 18 digit SFDC IDs.

Please mark this as the best solution if it helps.

Best Regards,
Nagendra.P
This was selected as the best answer