How to Avoid Validation Rules Using Salesforce Flow

In Salesforce, when we add a validation rule to any object, it prevents users from entering incorrect data. We can create a flow to avoid the validation rule and create the record.

In this article, we will learn how to avoid validation rules using Salesforce Flow, with real-time examples and explanations.

What is the Validation rule in Salesforce?

In Salesforce, a validation rule prevents incorrect data from being entered and requires the user to verify that the data meets certain criteria before saving the record.

If the user enters incorrect data, the validation rule displays an error message and prevents the record from being saved to the database.

Let’s take a Scenario while working as a Salesforce Admin for a US-based Organization that provides software solutions.

I was assigned the task of implementing a screen flow to bypass the validation rule so that, if the user enters a value that doesn’t meet the validation criteria on the record page, the record page returns an error.

But when the user tries to create a record through the screen flow, then the record should be created.

Avoid Validation Rules Using Salesforce Flow

For example, I have applied a validation rule to the opportunity object so that when the Opportunity Stage is ‘Closed Won,’ any user who tries to update that record will receive an error message, and the record will not be updated.

Prerequisites

I have created a validation rule on the opportunity object so that the opportunity record should not update when the opportunity stage is ‘Closed Won.’

Bypass Validation Rules Using Salesforce Flow

In this opportunity record, the Stage is ‘Closed Won,’ and the Lead Source is ‘Web.’

Bypass Validation Rule Using Salesforce Flow

Now I’m going to update Lead SourceWeb‘ to ‘Email.’ As I clicked on the Save button, I got an Error, and the record was not updated.

Avoid Validation Rules Using Salesforce Flow

Now, we need to create a Date/Time and a Formula field with a Checkbox. This field does not need to be added to the page layout, and these fields are needed while creating the flow. The Formula for the Checkbox field is as follows:

Flow_Bypass_Date_Time__c> NOW() - 0.00005787037037037037

Initially, the checkbox is Unchecked(False). This formula will make the checkbox checked (True) for four to five seconds when the Date/Time field is greater than NOW().

We will pass the value in the Date/Time field while creating the Flow.

Create Screen Flow in Salesforce

  • Log in to Salesforce Org. -> Click on the Setup -> Home Tab -> In the Quick Find Box, Search for Flows. You will see an option under Process Automation -> Click on Flows.
    • Then, click on the New Flow button to create a new flow.
    • Here, we want to try to update the opportunity record by bypassing the validation rule using Screen Flow.
    • To do that, create a flow with the Screen Flow component. Click it, then click the Create button.

Now, we will create the following elements in the flow, as shown in the diagram below.

How to a Create Bypass Validation Rules in Salesforce Flow

1. Get Records Element(Fetch Opportunity Records)

First, we have to create a New Resource and store the Opportunities ID in it. To do that, we need to create a New Variable. To do that, click on the Manager tab, and then you will see the New Resource option. Click on it.

  • Then, in the Resource Type, select Variable Type. Enter the API name, the same as recordid; do not change it. Select Data Type as Record.
    • In the Object field, select Opportunity and click the checkbox for Available for Input and Output.
    • Then click on the Done button.
Use Bypass Validation Rule in Salesforce Flows

To update records that avoid the validation rule, we need to access them via the opportunity object.

For that, we need to add the Get Records element by clicking on the ‘+ Add Element‘ icon. Enter a Label for it; the API Name will populate automatically.

Now, select the object from which you want to fetch records. Here, I have selected the Opportunity object.

Then, in the Filter Case Records, map the opportunity fields with screen component fields.

Use Bypass Validation Rule in Salesforce Flow

2. Adding Fields into Screen Canvas

Now, we have to add a Screen to the Canvas. To do that, click on the Elements tab in the Toolbox. You will see the Screen element under the Interaction drag-and-drop screen component on Canvas.

  • Then, enter the Label and API Name into the Screen component.
  • Now, we need to create some fields. Here, I have created required fields on the opportunity object that will automatically populate the Label and API Name.
  • In the Screen Component, we need to add the following fields as mandatory. We can also add the optional fields, but the required field must be added.
    • Opportunity Name:
    • Close Date:
    • Lead Source:
  • To fetch the picklist values, we need to create a New Resource. Select Picklist Choice Set as the resource type and enter the API Name it will use to assign the screen picklist field.
How to Create Bypass Validation Rule Using Salesforce Flow

Here, you can see the created resource of the picklist choice set we need to apply to the Choice field.

Create Bypass Validation Rules Using Salesforce Flows

We can also configure the Screen Footer. You can see I have used a Custom Label for the Next button and also hidden the Previous button.

Bypass Validation Rule Using Salesforce Flows

3. Update Records Element(Avoid Validation Rule)

Now, before updating the record in the object, we need to bypass the validation rule that creates a New Resource for ‘Formula‘ as ‘Type‘.

Enter the API Name to use as the value. The Data Type will be Data/Time. In the Formula Editor, you need to enter NOW(). This function returns the current time.

Create Bypass Validation Rule Using Salesforce Flow

Now add the Update Record element, use the specified condition to identify records, and set fields individually to find the records to update and set their values.

Select Opportunity Object, and to filter opportunity records, add the following condition:

Opportunity ID = recordid(from resource)>Opportunity ID.

  • Now, we will set the formula resource we created earlier for the Date/Time field.

Flow_Bypass_Date_Time__c(Object Field) <– Now(Created Formula Resource).

  • When we create a Date/Time field in the object, we don’t have to assign any value to it, nor do we apply it to any page layout. Now, using this formula, we have assigned the Current time to the Date/Time field.
  • Initially, the Checkbox Formula was (Flow_Bypass_Date_Time__c > NOW() – 0.00005787037037037037). Now, the Date/Time field has assigned a value NOW().
  • That means the Flow_Bypass_Date_Time__c field will be greater than Now(), so it will be Checked(True) for four to five seconds.
Create Bypass Validation Rule Using Salesforce Flows

4. Update Records Element(Update Opportunity Records)

In the steps above, we bypassed the validation rule, so we now need to update the records we changed.

To do that, we need to add the Update Records element, use the specified condition to identify the records, then set fields individually to find the records to update and set their values.

Select Opportunity Object, and to filter opportunity records, add the following condition:

  • Opportunity ID = recordid(from resource)>Opportunity ID.
Use Bypass Validation Rules in Salesforce Flow

Then, we need to assign Screen Fields values to the Object Fields so we can set the field values for the opportunity records.

Fields(Opportunity Object)Values(Screen Fields)
NameOpportunity Name
Close DateClose Date
Lead SourceLead Source
Use Bypass Validation Rules in Salesforce Flows

5. Save Flow

After setting up all labels and conditions, click the Save button to save the flow. For that, we need to enter the Flow Label. The API Name will automatically populate as we click the text box. The Description is optional; we can introduce our flow shortly.

6. Debug & Activate

After saving the flow, click on the Debug button. Then click on the Activate button; always remember to debug the flow before activating it. It’s good practice to use flow.

How to a Create Bypass Validation Rules in Salesforce Flow

7. Make Some Changes in the Validation Rule

  • Now, we need to make some changes in the Opportunity Validation Rule, for that go to the validation rule and Edit as follows:
ISPICKVAL (StageName, "Closed Won") && FlowBypassCheckbox__c = False
  • Here, we have set FlowBypassCheckbox__c = False, meaning that when the checkbox is false, we cannot update the record. This condition must also be true for validation to apply.
  • This means the validation rule will not apply when the Checkbox field we created earlier is unchecked (False). Using Bypass, we have created a formula to make the Checkbox True for four to five seconds.
  • It’s only triggered while using Flow. When you try to update a record in Org, it throws an error.
Create Bypass Validation Rules Using Salesforce Flow

7. Proof of Concept

Now, go to the Opportunity Records and copy any Opportunity Name whose Stage is Closed Won.

How to Create Bypass Validation Rule Using Salesforce Flows

After making changes to the validation rule, click the Debug button to check whether the flow is working properly.

As you click on the Debug option, you need to paste the copied opportunity name into the recordid field and click on the Run button.

This means we will update this record and check whether validation was bypassed.

How to Create Bypass Validation Rules Using Salesforce Flows

Now update the values in the fields we created in the Screen Component to whatever you want. Then click on the Save button.

If your flow has worked successfully, you will get All Done message.

How to Create Bypass Validation Rule in Salesforce Flows

Go to the Opportunity Record list to check whether the record has been updated with the value we entered.

Here, you can see that the Record has been updated with the value we entered. That means the Flow is working properly.

How to Create Bypass Validation Rules in Salesforce Flows

This is how we can bypass the validation rule using Salesforce Flow.

Conclusion

I hope you have an idea about Salesforce’s validation rules. We have also seen how to avoid validation rules using Salesforce Flow with real-time scenarios and explanations. After creating the flow, we tested it to see how it worked and checked whether records were updating.

You may like to read:

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.