$Profile.Name Validation Rule help - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Alice TannerAlice Tanner 

$Profile.Name Validation Rule help

Man, I am just NOT a natural at these formulas...!!  So our current set up is that no one can update an oppty to 100% (or modify a closed oppty) unless you're a System Admin.  This is accomplished via the following validation rule on opportunities:

AND ( 
$Profile.Name <> "System Administrator", 
ISPICKVAL(StageName, "100% = Closed"))

We now need to allow a second profile, "COMPANY Finance User", to modify closed opportunities for some integration work w/our financial system.  I tried to allow this by adding them to the formula, as follows:

AND ( 
OR($Profile.Name <> "System Administrator", $Profile.Name <> "COMPANY Finance User"), 
ISPICKVAL(StageName, "100% = Closed"))

..but that just breaks the formula entirely and NO ONE can close/won or modify a closed oppty when it's written that way.  Help!

Alice  
Best Answer chosen by Miglena (Salesforce.com) 
Shannon DykesShannon Dykes
Oh wait... try 

ISPICKVAL(StageName, "100% = Closed") && NOT(OR($Profile.Name = "System Administrator", $Profile.Name = "COMPANY Finance User" ))

*I'd recommend the profile ID in there too, but the name worked with this in my org. If you ever changed the name of the profiles, you'd have to change this.. but if you use:

ISPICKVAL(StageName, "100% = Closed") && NOT(OR(
$Profile.Id ! = "System Administrator profile Id", $Profile.Id ! = "COMPANY Finance User profile id" ))

You won't ever have to change your validation rule.

All Answers

Shannon DykesShannon Dykes
Last code was messed up, try this one:

($Profile.Name <> "System Administrator" || $Profile.Name <> "COMPANY Finance User")  
&& ISPICKVAL(StageName, "100% = Closed")



 
Alice TannerAlice Tanner
I had not! ...although I just did, unfortunately to the same result as before: neither profile can manipulate the record now. 

(Just tried w/the revised code as well. What on earth am I missing..) 
Javier GonzalezJavier Gonzalez
I would recommend using the profile ID instead. Try this:

AND(IsClosed, $Profile.Id !="insertyouradminprofileidhere", 
$Profile.Id !="insertotherprofileidhere")
Shannon DykesShannon Dykes
Oh wait... try 

ISPICKVAL(StageName, "100% = Closed") && NOT(OR($Profile.Name = "System Administrator", $Profile.Name = "COMPANY Finance User" ))

*I'd recommend the profile ID in there too, but the name worked with this in my org. If you ever changed the name of the profiles, you'd have to change this.. but if you use:

ISPICKVAL(StageName, "100% = Closed") && NOT(OR(
$Profile.Id ! = "System Administrator profile Id", $Profile.Id ! = "COMPANY Finance User profile id" ))

You won't ever have to change your validation rule.
This was selected as the best answer
Alice TannerAlice Tanner
shayd - THAT WORKS! you're my savior. thanks so much! :) 
Sunil ShahSunil Shah
Thanks Alice for posting the question. Thanks guys for the answers :)
Tom KovarTom Kovar
I have found, to my big surprise, a funny thing today, as my validation rule checking the $Profile.Name for "System Administrator" was not working.
Even though the profile name is "System Administrator" (both displayed in the UI and returned by SOQL), $Profile.Name returns the value of "Systemadministrator". Made my day...
Robin KlemmRobin Klemm
@Tom Kovar: Thank you SO MUCH for this. I was struggling like crazy because of this...
Volkov EgorVolkov Egor
@Tom Kovar  The reason why $Profile.Name <> 'System Administrator' is not working might be due to the default language set at Company level (probably it's Deutch). If it's different than English then all standard profile names are translated. If your organization uses language different than English then there is no longer a profile called 'System Administrator' - it is translated to the language used. This applies also to validation rules, workflows, etc. 
Kevin KlerkxKevin Klerkx
@volkov Egor, you're a lifesaver. That fixed the issue for me !