Salesforce Flow Automation: The Bypass Toggle

The Bypass Toggle: avoid VR errors in Salesforce Flow

Salesforce does not have a native way to bypass Validation Rules. So, any time I do a data load or have a Record-triggered Flow update a record, about 1000% of the time, I will run into a VR that keeps me from completing my job. 

How many times have you received the Apex Exception Email with the error: FIELD_CUSTOM_VALIDATION_EXCEPTION? 

The Bypass Toggle method allows me to programmatically bypass VRs without turning them all off and then back on again after a job. This saves me time and a bunch of headaches with Flow errors.

Let’s dive into how to set up your very own Bypass Toggle.

Method

  1. Create the Toggle field
    1. Add a new checkbox field named ‘Toggle__c’ to your object.
    2. No need to add the field to any page layouts.
    3. Grant all profiles the necessary permissions to access this field.
  2. Update your Validation Rule
    1. Modify your existing validation rule to include the following condition: ‘NOT(ISCHANGED(Toggle__c))’.
    2. This will ensure the validation rule does not fire if the Toggle field is changed.
  3. Create a formula variable in your Flow.
    1. In the Flow that updates your record, create a formula variable called ‘ChangeToggle’.
    2. Use the following IF formula for the variable: ‘IF(Toggle__c = TRUE, FALSE, TRUE)’.
    3. This ensures that the Toggle field value will always change regardless of its current or prior state.
  4. Set the Toggle in the Flow
    1. In the Flow element that updates your record, set the value of the Toggle field using the ‘ChangeToggle’ formula variable. Ie: ‘Toggle__c’ = ‘ChangeToggle’.

Don’t forget the Data Load

This method will also help you when doing a data load.

When exporting your CSV or a SOQL SELECT, include the Toggle checkbox.

Now when updating your object, along with any other update, remember to flip your Toggle from current state (TRUE or FALSE) to the opposite state.

This will also ensure your VR doesn’t fire on updates to your object.

Business Result

Now, when a user creates or edits a record, the Flow updates the Toggle field value. Same thing occurs when you update the database via a data load. This change prevents the validation rule from triggering, allowing the record to be successfully updated. This saves a ridiculous amount of time and frustration by avoiding those pesky VR errors. Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *

Let's talk about growing your brand

Explore use cases for your industry
Get strategy and solutions information
Learn how to grow your business