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
Forrest MulduneForrest Muldune 

Apex Trigger - Cross Object User and Opportunities

All,

I am here seeking help for Apex Trigger coding. 

In the User Object I created a Custom Picklist field name Asset_Manager_Group__c with the values Group A, Group B, Group C, Group D

In Opportunities, I created another Custon Picklist field name Asset_Manager_Group__c with the values Group A, Group B, Group C, Group D

Apex Trigger Request - I am requesting if someone can help me create a trigger.  When an administrator selects a value in the Asset_Manager_Group__c in the User Object and saves the record, the same value will automatically populate in the Asset_Manager_Group__c field in the associated opportunity record based on Opportunity owner. For example if Asset_Manager_Group__c = Group A in Joh Doe User object, the related Opportunity records own by John Doe will have the same value in the Asset_Manager_Group__c field.


I really appreciate the help. Thank you.
 
Best Answer chosen by Forrest Muldune
Paul S.Paul S.
You don't actually need a trigger for this.  You can simply create a create a formula field on the opportunity object that will reference the field on the  user object.  See the path in this screenshot.  Because you're pulling the value of a picklist, the actual formula using the below example would be:

TEXT(Owner:User.pjsdev__Manager_Group__c)

User-added image

All Answers

Paul S.Paul S.
You don't actually need a trigger for this.  You can simply create a create a formula field on the opportunity object that will reference the field on the  user object.  See the path in this screenshot.  Because you're pulling the value of a picklist, the actual formula using the below example would be:

TEXT(Owner:User.pjsdev__Manager_Group__c)

User-added image
This was selected as the best answer
Forrest MulduneForrest Muldune
If I create the formula field in Opportunity, can I use this field in a Work Flow Rule Criteria? When the value in the formula field changes, would this create and edit a workflow Rule?
Paul S.Paul S.
I believe you can.  What's your use case there?
Forrest MulduneForrest Muldune
I want to use this Workflow Rule Criteria in Opportunities


AND(
  ISCHANGED(OwnerId),
   OR(Owner.Profile.Name = "Account Manager",
      Owner.Alias = "fmuld",
       ISPICKVAL(Owner.Asset_Manager_Group__c, 'Group B' )


Will this work?
 
Paul S.Paul S.
That should work.  Let me know if it doesn't.
Forrest MulduneForrest Muldune
Paul,

I will test it to see if it works. I also added some Email Alerts and Field Updates to it. Thanks and I will send you some feedback.
Forrest MulduneForrest Muldune
Paul, 

thanks for the recommendation, it works!

Forrest