There are a few approaches you can take here, which I will list in order of preference. These should work just about anywhere merge fields can be used.
Create a Custom Permission
You can check if someone has a Custom Permission
in a formula as follows:
$Permission.My_Custom_Permission__c
Steps:
- Create
Custom Permission
- Add it to a
Permission Set
- Assign that
Permission Set
to anyUser
you wish to exempt from validation
Hierarchy Custom Setting
If you don't find the above palatable for some reason, you can also check a Hierarchy Custom Setting
in a formula as follows:
$My_Hierarchy_Setting__c.Is_Exempt_From_Validation_X__c
Steps:
- Create
Hierarchy Custom Setting
- Add exemption field
- Set
Org Wide Default
for this field to false - Set value to true for any
User
you wish to exempt from validation
UsernameAlias
You can check against aan UsernameAlias
in a way that at least works in all environments as follows:
$User.Alias = "analias"
Username
Somewhat less clean than Alias
, but you would check against a Username
as follows:
BEGINS($User.Username, "[email protected]")
User Id
I would not adopt this approach unless you have compelling reasons none of the above are a good fit:
$User.Id = "00550000000lxVg"