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
Paul ZamskyPaul Zamsky 

Update Contact Through Account Contact Role


I"m pretty new to apex and coding in general but have done a few triggers on our platform so far. Once that I need to get done is one that can update the account manager from "Account" to "Contacts" through the "Account Contact Role" object. Because we have severl company for several users we only use the account contact role and not the lookup in contact. The code I got so far is below. I've been stuck for a couple of days and was wondering if anybody had any suggestions or could help.



trigger RMUpdateContactRole on Account (after update) {
    String relationshipmanager;
    String CompanyID;
    for(Account act :
        {relationshipmanager = act.relationship_manager__c;
         CompanyID =;}

     List<AccountContactRole> AcrList =[SELECT contactid, accountid FROM AccountContactRole WHERE accountid =: companyid];
     List<Contact> contactlist = [SELECT id, relationship_manager__c FROM Contact WHERE id IN: AcrList.contactid];
    	for(Contact cnt:contactlist)
            cnt.relationship_manager__c = relationshipmanager;
    	update contactlist;
SonamSonam (Salesforce Developers) 
I've gone through the code and understand that you are trying to acomplish the following:
Update contact each time a new Account contact role is created with the field called relationship manager.
This field gets its value from the Account itself.

Basically, the trigger you have written will only execute when the Acocunt is updated, not when a Account role is created, reason being this is a separate object: Accountcontactrole( I think doesn't accept triggers.

Please correct me if my understand is wrong.