0

I have written a Validation Rule that I need to include a profile exception in. My rule is below and I can't figure out how to add an exception so that System Administrators can bypass this rule. Can someone please help me add in the Sytem Administrator exception. Thanks!

My rule is: If a field equals a certain value, another field (multi select picklist) cannot have a certain value removed from it unless you are a system admin.

Please see Rule below:

if( Field__c == 'Value', 
  if( 
    OR( 
      INCLUDES(Custom_Field__c,'Value') 
    ), 
    True, 
    False 
  ), 
False 
)
3
  • You have some redundant logic here. Can you describe in words what the validation rule is supposed to do?
    – David Reed
    Commented Feb 28, 2018 at 21:04
  • Salesforce Help has good examples of validation rules including how to set profile exceptions. Commented Feb 28, 2018 at 21:10
  • My rule is: If a field equals a certain value, another field (multi select picklist) cannot have a certain value removed from it unless you are a system admin.
    – Jord
    Commented Feb 28, 2018 at 21:14

3 Answers 3

9

Checking by profile should not be done these days. It's inflexible, and doesn't allow you to respond quickly to changes. Instead, use a custom permission. First, create a new custom permission. Second, assign it to the profile(s) you want to exempt from your validation rule. Third, create your validation rule, which might look like this:

AND(NOT($Permission.Allowed_To_Do_Something),
    Field__c == 'value', 
    INCLUDES(PRIORVALUE(Other_Field__c),'value'),
    NOT(INCLUDES(Other_Field__c, 'value')))

This says: "If the user does not have permission to bypass this rule, and the first field is a specific value, and the multi-select picklist value previously contained a value, and the multi-select list no longer contains this value, trigger this validation rule."

Edit: edited based on rule description. Please feel free to adjust.

1
3

I am not sure I'd recommend hardcoding a profile name, but if you absolutely have to do it, you do it this way:

$Profile.Name = "System Administrator"

The above line will compare the user's profile to the exact name, so make sure you have no typos.

2
  • Could always put the profile name in a custom setting e.g. $Setup.Test_Custom_Setting__c.Profile_Name__c. Can't do this with list settings though. Commented Feb 28, 2018 at 21:26
  • 1
    That's definitely up to the OP's discretion, but it's a great point. Alas, it is only good for one profile.... or many fields. :) Thanks @AntonioManente! Commented Feb 28, 2018 at 21:26
0

You can slim this down quite a bit by cutting the redundant logic and inserting the System Administrator check.

AND(Field__c == 'Value', 
    !INCLUDES(Custom_Field__c, 'Value'),
    $Profile.Name != "System Administrator"
   )

Note that this isn't exactly what you described; it doesn't check for a value to be removed, but checks whether it is present at all in your multi-select picklist. However, that's probably a fair solution for what you're aiming at.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .