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
Rafael MottaRafael Motta 

How can I create a user who inherits other users?

I have an approval process in Oportunities object, that requires to be approved by the user configured in accounts (look up field ), which would come to be the Comersial Manager. this manager may be different for each account record.

Is there some way to put that user in fine as approver.
 repeat .. I can not put an espesific user in the process builder because the manager can be variable with each account and I can not put it in a queue, because the Aproval Process has to be aprove by Comersial Mnager.


I have tried to do it by configuration but I do not see how to do it, the way I see more possible to do is with a formula that obtains that field (user) and place it in opportunities, but I do not know how to assign it as approver.

I have no idea how to do it by code so I contact you mainly to see if it is possible to do this by code.

User-added image

Best regards
Ahmad J. KoubeissyAhmad J. Koubeissy
Create a custom lookup field on the opportunity. It should be related to User. let's name it : Acc_Comersial_Manager__c
Now you have to create a trigger on the opportunity before insert in order to copy the comersial manager from the account to the opportunity.
trigger OpportunityBeforeInsert on Opportunity (before insert){
      set<string> AccountsID = new set<String>();
      map<string,string> MapAccIDtoCommersialManager = new map<string,string>();
      for(opportunity opp:trigger.new){
             AccountsID.add(opp.accountid);
      }
      for(Account acc: [select id,comersial_manager__c from account where id in :AccountsID]){
            MapAccIDtoCommersialManager.put(acc.id,acc.comersial_manager__c);
      }
      for(opportunity opp:trigger.new){
            opp.Acc_Comersial_Manager__c = MapAccIDtoCommersialManager.get(opp.accountid);
      }
}
If the comersial manager could be changed on the account, you have to create a trigger also on the account after update in order to change the manager on all the opportunities related to this account.

Thanks for marking as best answer if this helps you,
Best Regards.