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
iSqFt_ADiSqFt_AD 

Need Help With Trigger - If Field says Yes, reassign Account to Owner's Manager

I am not a developer but I know this should be a fairly simply trigger to write. Here is the expected result:

 

If the custom formula text field Up_for_Reassignment__c is "YES", the Account should be reassigned to the Account Owner's manager (via the Manager field on the User page).

 

I need this to happen automatically at the moment the Up_for_Reassignment__c field changes from NO to YES. 

 

Anyone?


Thanks!

hemantgarghemantgarg

I hope below snap will help you :-

 

 

Set<Id> ownerSet = new Set<Id>();
for(Account ac :Trigger.New){
      if(acc.<fielName>){
	ownerSet.add(ac.ownerId);
      }
}

for(User u : [select ManagerId from User where Id IN:ownerSet]){
    ownerMap.put(u.id, u);
}

for(Account acc :Trigger.new){
       if(acc.<fielName> && ownerMap.containsKey(ownerId)){
                acc.ownerId = ownerMap.get(ownerId).ManagerId;
         }
}

 

 

    

iSqFt_ADiSqFt_AD

Thank you Hermant!

 

Two questions though:

 

1. I do not see this code referencing my custom field Up_for_Reassignment__c anywhere. How will this work then?

2. What event do I need to set this for so that it automatically looks for the match without any update required?


Thanks.