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 

Trigger to populate a Read Only Text field with Owner Role on Opportunity

Does anyone have a snippet of code that might work similar to a workflow rule, but that when the Opportunity Stage becomes Closed Won, the Opportunity Owner's Role is populated into a read-only text field?

 

Thank you,

raseshtcsraseshtcs

 

Set<Id> uIds;
for(Opportunity o : Trigger.New){
uIds.add(o.OwnerId);
}
Map<Id,User> userOppty = new Map<Id,User>([Select Id, Role from User where Id IN :uIDs]);
for(Opportunity o : Trigger.New){
if(o.Stage == 'Closed Won'){
o.ReadOnlyField = userOppty.get(o.OwnerId).Role;
}
}

 

 This should work (Not Tested)

iSqFt_ADiSqFt_AD

Thank you! I will test in our sandbox and mark this as the solution if it works.

iSqFt_ADiSqFt_AD

I have no experience with Triggers, so let my humiliation show...

 

I copy and pasted your code into a new trigger in the sandbox and I keep getting errors for the "<".


What do I need to edit in this code to make it work?

 

Thank you,