Sub topic 12
Bypassing rules with custom permissions
This chapter assumes you can write a basic validation rule formula and know how to open Setup and the Object Manager. Some rules need exceptions. A data load, an integration user, or an administrator fixing legacy records may have to save data that normally breaks a rule. The usual approach is to add a bypass clause that checks a custom permission.
Why use a custom permission
You could hard-code a profile name or user ID in the formula. That breaks when the name changes, and it differs between sandbox and production. A custom permission is a named flag you create once. You grant it through a permission set, and formulas read it with the $Permission global variable.
This gives you three benefits:
- The bypass is visible in the formula and easy to audit.
- You grant or remove access in a permission set, without editing any rule.
- One permission can cover many rules.
Create the bypass
- In Setup, search for Custom Permissions and click New.
- Set the label to
Bypass Validation Rules. The API name becomesBypass_Validation_Rules. - Save, then create a permission set (for example,
Data Load Bypass). - In the permission set, open Custom Permissions, edit, and add
Bypass_Validation_Rules. - Assign the permission set to the users who need it.
Add the clause to a rule
Place the bypass check first, wrapped in NOT. The rule only fires when the user does not hold the permission and the data is invalid.
AND(
NOT($Permission.Bypass_Validation_Rules),
ISPICKVAL(StageName, "Negotiation/Review"),
OR(ISBLANK(Amount), Amount <= 0)
)$Permission.Bypass_Validation_Rules is true for users who hold the permission. NOT turns that into false, so AND is false and the save goes through. For everyone else, the original conditions decide.
Good practice
- Name the permission clearly and grant it to as few people as possible. A bypass is a way around your data quality controls.
- Use it for integration users and planned data loads. Remove the assignment when the load finishes.
- Consider a separate permission for a single sensitive rule if you do not want it covered by a broad bypass.
- Add the clause to every rule that needs it. A rule without the clause will still block bypass users.
Common errors
- Misspelled API name. The formula editor rejects an unknown
$Permissionname when you save. - Missing
NOT. Without it, the rule fires only for bypass users, which is the opposite of what you want. - Permission not assigned. Creating the custom permission is not enough. A permission set must include it and be assigned to the user.
- Forgotten rules. If a bypass user is still blocked, check whether that rule contains the clause.
Exercise
A rule's formula is AND($Permission.Bypass_Validation_Rules, ISBLANK(Phone)). Users with the bypass are now blocked for blank phones, and everyone else can save. What is wrong, and how do you fix it?
Show answer
The bypass check is missing NOT. The condition is true only for users who hold the permission. Change it to AND(NOT($Permission.Bypass_Validation_Rules), ISBLANK(Phone)).