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
Maddie NewstromMaddie Newstrom 

Autofill Lead source based on user role

I am looking to auto populate lead source based on a certain user role and am having trouble figuring it out. I tried process builder and other methods with no luck. Any advice?
Scott Nelson SolutionistScott Nelson Solutionist
My first thought is to try profile instead of role. Would have to know more details about the process and requirements to go beyond that. 
Maddie NewstromMaddie Newstrom
I created a custom formula field on the lead to pull in user role and that did not work. after doing a little more research it looks like I need to create a before trigger to do this before the lead is saved. However i have never created a trigger before.
Scott Nelson SolutionistScott Nelson Solutionist
A trigger in this case is probably the simplest approach. That said, I would re-examine the case. If all leads are manually entered, there is a hack in Process Builder you can do get around this. The problem you are having is that the process is trying to update the record before it has been saved. You can stick a wait step with the wait period as 0 hours n between to delay your update and then it will work.

If leads are loaded in bulk, the user doing the bulk load may not have a role. Profile may be a better criteria. 

HTH
Maddie NewstromMaddie Newstrom
We have a validation rule in place to require lead source. It gives me the validation rule error before saving when i build out the process builder. know of any better way to build this?

Goal - make sure lead source is always filled out when new leads are being created manually (validation rule)
Hiccup - team members are choosing the top option versus choosing their specific picklist value 
my thought - default their picklist value based on user role!
Scott Nelson SolutionistScott Nelson Solutionist
I'm not clear on whether all leads are entered manually or if the issue is only with manual leads.
If the former, you can use your formula field as a controlling field for the picklist (see In that case you can make the role a controlling field for the). Make the default picklist value a blank (or "--Pick One--") and make that and null as invalid in the validation.