How to Bypass Validation Rules Using Salesforce Flow

In Salesforce, when we add a validation rule on any object, it restricts the user from entering incorrect data. We can create a flow to avoid conditions of the validation rule and create the record.

In this Salesforce tutorial, we will learn about what validation rules are in Salesforce, and we will also see how to bypass validation rules using Salesforce Flow with real-time scenarios and explanations.

What is the Validation rule in Salesforce

In Salesforce, the validation rule restricts the user from entering incorrect data and requires the user to verify that the data entered meets certain criteria before the user can save the record.

If the user enters the incorrect data, the validation rule throws the error message and doesn’t allow saving the record in 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 screen flow to bypass the validation rule so that if the user enters a value that doesn’t meet validation criteria through Org, then it should get an error, but when he tries to create a record through screen flow, then the record should be created.

How to Bypass 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,’ if any user tries to update that record, it should get an error message, and the record should not get updated.

Prerequisites

1. 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

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

Bypass Validation Rule Using Salesforce Flow

3. 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.

Bypass Validation Rules Using Salesforce Flows

4. Now, we need to create a Date/Time and one Formula field with a Checkbox. This field does not need to be added to the page layout and these fields we need 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.

See also  Migrate Workflows and Process Builder to Salesforce Flow

Create Screen Flow:

5. Log in to Salesforce Org. -> Click on the Setup -> Home Tab -> In 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 on it and then click on the Create button.

Now, we will create the following elements in the flow according to the flow diagram displayed in the following Flow Diagram.

How to a Create Bypass Validation Rules in Salesforce Flow

1. Get Records(Fetch Opportunity Records):

6. 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

7. To update records bypassing the validation rule, we need to access them from the opportunity object. For that, we need to add the Get Records element by clicking on the Plus ‘+ Add Element‘ icon. Enter a Label for it; the API Name will populate automatically.

  • Now, you need to select an object from which you want to fetch the 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:

8. Now, we have to add a Screen to the Canvas. To do that, click on the Elements tab from 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 fields that are required in the opportunity object with the Label, and the API Name will automatically populate.
  • In the Screen Component, we need to add the following fields as mandatory. We can also add those fields that are not required, but the required field is what we must add.
  • 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

9. 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

10. 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(Bypass Validation Rule):

11. 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 it will 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

12. Now add the Update Record element and use the specified condition to identify records and set fields individually to find records to update and set their values. Select Opportunity Object, and to filter opportunity records, add the following condition:

See also  Auto-Update Custom Date field using Flow in Salesforce

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

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

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 and also don’t 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(Update Opportunity Records):

13. In the above steps, we have bypassed the validation rule, so now we need to update the records, which we will change. To do that, we need to add the Update Records element and use the specified condition to identify records and set fields individually to find 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

14. 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:

15. 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.

See also  How to Create Lookup field in a Salesforce Flow

6. Debug & Activate:

16. 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:

  • 22. 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 added FlowBypassCheckbox__c = False, which means that when the checkbox is false, we cannot update the record. This condition must also be true to apply validation.
  • This means the validation rule will not work when the Checkbox field that we created earlier is not Checked(True). 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 from Org, it will throw an error.
Create Bypass Validation Rules Using Salesforce Flow

7. Proof of Concept:

  • Now go to the Opportunity Records and copy any Opportunity Name which 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 the Record is updated with a value that 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 bypass validation rules using Salesforce Flow with real-time scenarios and explanations. After creating the flow, we saw how it was working and also checked whether records were updating.

You may like to read: