Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I'm looking for input on how to adjust an existing, working validation rule so that it doesn't fire when the running user is a specific Profile. Here is the existing rule:

AND( NOT(ISBLANK(Energy_Specialist__c)),
ISPICKVAL( Account.Audit_Provider__c , 'CET'),
NOT(ISPICKVAL( Energy_Specialist__r.Type__c, 'CET')))

I don't want it to fire for a specific Profile so I tried adding the last line below:

AND( NOT(ISBLANK(Energy_Specialist__c)),
ISPICKVAL( Account.Audit_Provider__c , 'CET'),
NOT(ISPICKVAL( Energy_Specialist__r.Type__c, 'CET')),
$User.ProfileId <> 00eM0000000QTa7  )

but I keep getting syntax errors saying I missing an ")" even after I add additional ending parenthesis. I'm also thinking that I might need to disclude more than 1 Profile in the future too. Any help would be appreciated.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

The error you are getting is because you didn't use quotes ('') around the Profile Id. Not that the error message gives you any insight into that, but thats whats causing the issue. Try this

AND(
     NOT(ISBLANK(Energy_Specialist__c)),
     ISPICKVAL( Account.Audit_Provider__c , 'CET'),
     NOT(ISPICKVAL( Energy_Specialist__r.Type__c, 'CET')),
     $User.ProfileId <> '00eM0000000QTa7'
)

I would also recommend using the profile Name as opposed to the hardcoded ID. Hardcoding IDs is never best practice.

$Profile.Name <> 'YOUR PROFILE NAME'

EDIT

From your comment, if you want to add another excluded profile, just add another condition to the AND statement like below.

AND(
     NOT(ISBLANK(Energy_Specialist__c)),
     ISPICKVAL( Account.Audit_Provider__c , 'CET'),
     NOT(ISPICKVAL( Energy_Specialist__r.Type__c, 'CET')),
     $Profile.Name <> 'CORE Profile',
     $Profile.Name <> 'System Administrator'
)
share|improve this answer
    
That was exactly it! I wanted to use the Profile name but when using the Insert field button/wizard, the User>Profile Name was not available, only ProfileID. –  user7417 Aug 25 at 20:14
    
Yes, its not under user, its under profile when using the wizard. Glad it worked for you. :) –  sfdc_ninja Aug 25 at 20:17
    
Would you know how I could set it to disclude 2 Profiles? I updated to not fire when a specific Profile Name as you stated and fired only when I expected which is great but when I added an or to it, it errors: AND(NOT(ISBLANK(Energy_Specialist__c)), ISPICKVAL( Contact.Account.Audit_Provider__c , 'CSG'), OR (NOT(ISPICKVAL( Energy_Specialist__r.Type__c, 'RTL'))), (NOT(ISPICKVAL( Energy_Specialist__r.Type__c, 'HES'))), $Profile.Name <> "CORE Profile" || "System Administrator") –  user7417 Aug 25 at 20:22
    
Just updated the answer to reflect. –  sfdc_ninja Aug 25 at 20:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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