Bypass Your Validation Rules
Learning Objectives
After completing this unit, you’ll be able to:
- Implement bypass switches in your validation rules.
At some point, you’ll probably encounter a situation where you need to update data, but are blocked by validation rules. Or you might have certain users that you want to be exempt from specific validation rules. Enter the bypass switch. In this unit, you learn how to give users permission to bypass one or more validation rules.
Bypassing Validation Rules
A carefully designed validation rule might rarely need a bypass. Let’s say you’ve implemented ISCHANGED
and ISNEW
in your formulas. Your validation rules should only fire when data is changed to no longer meet your requirements. Typically, bypassing validation rules may be needed to correct historical data or perform data loads.
Ready to build a validation rule that has a bypass? Let’s create a validation rule that prevents users from clearing the product interest form on a Lead once it has been populated. You also want to let specific users clear the field. In the steps below, you create a custom permission, assign that permission to a permission set, assign that permission set to a user, and finally create a validation rule that only evaluates to true when a user doesn’t have that permission. That may have sounded like a mouthful, but let’s take it step by step.
Create a Custom Permission
If you need to bypass a validation rule, the first step is to create a custom permission.
- In Setup Quick Find, enter
Custom Permissions
. - Click Custom Permissions.
- Click New.
- Fill in the following information:
- Label:
Bypass Lead Validation Rules
- Name:
Bypass_Lead_Validation_Rules
- Description:
Allows users to bypass lead validation rules.
- Label:
- Click Save.
Create a Permission Set
Now that you have a custom permission, you need to assign it to a permission set and assign the permission set to a user.
- In Setup Quick Find, enter
Permission Sets
. - Click Permission Sets.
- Click New.
- Fill in the following information:
- Label:
Bypass Lead Validation Rules
- Name:
Bypass_Lead_Validation_Rules
- Description:
Allows users to bypass lead validation rules.
- License: None
- Label:
- Click Save.
- On the Permission Set Overview screen, scroll down until you see Custom Permissions.
- Click Custom Permissions.
- Click Edit.
- Add the Bypass Lead Validation Rules Custom Permission to the Enabled Custom Permissions section.
- Click Save.
- Click Manage Assignments.
- Click Add Assignment.
- Check the box next to your name.
- Click Next.
- Click Assign.
- Click Done.
Tip: You could use a Session-Based Permission Set and build a Flow that lets users choose when to apply that Permission Set to their current session. This ensures that all users must adhere to validation rules by default. When they encounter a situation that truly requires a bypass, they can access your flow to give them the super powers to save the record. Learn more about this topic in the Session-Based Permission Sets and Security module on Trailhead.
Create a Validation Rule with Bypass
Next, you create a validation rule on Lead that prevents users from clearing the Product Interest field once it is populated.
- From Setup, click Object Manager.
- Click Lead.
- In the left sidebar, click Validation Rules.
- Click New.
- Enter the following properties for your validation rule:
- Rule Name:
LEAD002_Product_Interest_Required
- Description:
Once Product Interest has been populated, it cannot be cleared.
- Error Condition Formula:
- Rule Name:
AND( NOT( $Permission.Bypass_Lead_Validation_Rules ), NOT(ISBLANK(TEXT( PRIORVALUE( ProductInterest__c )))), ISBLANK( TEXT( ProductInterest__c )) )
d. Error Message: Once Product Interest has been populated, it cannot be cleared [LEAD002]
e. Error Location: Field, Product Interest
6. Click Save.
Let's break down the validation rule formula step by step.
NOT( $Permission.Bypass_Lead_Validation_Rules )
: This condition checks if the user does not have the permission to bypass lead validation rules. If the user lacks this specific permission, the formula evaluates to true.NOT(ISBLANK(TEXT(PRIORVALUE(ProductInterest__c)))
): This part of the formula verifies if the previous value of theProductInterest__c
field (before the current edit) is not blank. BecauseProductInterest__c
is a picklist, we have to use the TEXT function to be able to check if it is blank. If the previous value is not empty, the formula evaluates to true.ISBLANK(TEXT(ProductInterest__c))
: Finally, this part checks if the current value of theProductInterest__c
field is blank. If the field is indeed empty, the formula evaluates to true.
Now, let's put it all together.
The entire formula, with the AND operator wrapping the three conditions, evaluates to true only when all the conditions are met simultaneously.
- The user does not have the Bypass_Lead_Validation_Rules permission.
- The previous value of the ProductInterest__c field is not blank.
- The current value of the ProductInterest__c field is blank.
If all three conditions are satisfied (that is, the formula evaluates to true), the validation rule triggers, and the user will see an error message, preventing them from saving the record until the specified conditions are met. This validation rule helps ensure that when a ProductInterest__c value is changed from a non-blank value to a blank value, users must have the appropriate permission to bypass this validation or provide a new non-blank value for ProductInterest__c.