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

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
    I recently fell in love with Custom Settings.. ++ – EricSSH Mar 31 '15 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.