0

Use Case:

IF the Account Status (status is a a picklist) is "Pending Review" or "Active" Then Only Profile "CSX" and "" System Admin" can edit the record

I have Created this Validation rule

AND (

          OR($Profile.Name <> "System Administrator", $Profile.Name <> "CSX"),

          OR (ISPICKVAL(Status__c, "Active") , ISPICKVAL(Status__c, "Pending Review")),
          
          NOT (ISNEW()),

          RecordType.DeveloperName = "Licensee"

         )

The validation rule does not work as expected. When the CSX user logs in and edits the record, the user gets the 'WE hit a snag' error.
Similarly all other users including System Admin get the 'we hit the snag' error.

1 Answer 1

0

Remember that validation rules are better called invalidation rules. They tell you when data is bad, not when it's good. Don't try to construct this like you would construct an if() condition in Apex.

At first glance, the OR($Profile.Name <> "System Administrator", $Profile.Name <> "CSX") should be making your spidey-senses tingle.
A user can only have a single profile, so at least one of those comparisons will always return true. If one is always true, then the entire OR() is always true.

That OR() for your profile check should be an AND() instead. If a user is both not a sysadmin and not CSX, then there is a chance you want your rule to fire. Being a member of either one of those two profiles is sufficient to exclude that user from your rule.

AND (
    AND($Profile.Name <> "System Administrator", $Profile.Name <> "CSX"),
    OR (ISPICKVAL(Status__c, "Active") , ISPICKVAL(Status__c, "Pending Review")),
    NOT (ISNEW()),
    RecordType.DeveloperName = "Licensee"
)

You could simplify a little by pulling the profile checks out of the nested AND() (because the outermost operation is an AND()), but there's little harm in keeping that as is, and separating that section into its own "group" can help others read the validation rule.

Alternatively, you could create and assign a Custom Permission to manage this instead of relying on profiles.

You must log in to answer this question.

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