2

I have the following validation rule ;

OR( 
    AND( 
       Upper(MailingCountry) <> 'UK',     
       NOT(ISBLANK(TEXT(UK_Email_Consent__c)))
    ), 
    AND(
       Upper(MailingCountry) = 'UK',  
       ISBLANK(TEXT(UK_Email_Consent__c))
    )
)

I know to exclude system admins I need to include the following line

$Profile.Name <> "System Administrator"

In the validation rule above where do I add profile <> system admin

Looking forward to your help

many thanks

2 Answers 2

3

there are multiple ways to do that..

one option is to use IF function and exclude sys admin profile from the validation logic..

IF(
   $Profile.Name = "System Administrator" , FALSE ,
   OR( 
     AND( 
       Upper(MailingCountry) <> 'UK',     
       NOT(ISBLANK(TEXT(UK_Email_Consent__c)))
     ), 
     AND(
       Upper(MailingCountry) = 'UK',  
       ISBLANK(TEXT(UK_Email_Consent__c))
     )
  )
)

the other option is to use the AND function and wrap both the profile check and the current logic

AND(
   $Profile.Name != "System Administrator" ,
   OR( 
      AND( 
         Upper(MailingCountry) <> 'UK',     
         NOT(ISBLANK(TEXT(UK_Email_Consent__c)))
      ), 
      AND(
         Upper(MailingCountry) = 'UK',  
         ISBLANK(TEXT(UK_Email_Consent__c))
      )
   )
 )
2

You can also create a custom setting with a checkbox field that defaults to true, add your system administrator profile as a validation exemption.

Then in your validation rule, you would say something like "$Setup.customsettting.checkbox = True".

Putting it into a custom setting will allow you to reuse that criteria, and add to it as needed without having to update all of your validation rules. So, if you created a custom system admin profile down the road, you could just add that profile to the exemption list instead of adding it to each and every validation rule.

1
  • 1
    I recently fell in love with Custom Settings.. ++
    – EricSSH
    Commented Mar 31, 2015 at 16:57

You must log in to answer this question.

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