How to Add Validation to Screen Flow in Salesforce

In Salesforce, entering the values in the screen component in Salesforce Flow allows a system administrator to define custom logic and error messages and force the user to enter the correct data.

In this Salesforce tutorial, we will learn how to add validation to Screen Flow in Salesforce with real-time scenarios and step-by-step explanations.

What is the Validation Rule in Salesforce?

In Salesforce, the validation rules restrict the user from entering incorrect data in Salesforce records. If the user enters incorrect data, it throws an error message, and the record cannot be saved.

The validation rule verifies the data users enter in a record to meet the organization’s standards. A validation rule in Salesforce holds a formula or expression that accesses the data in one or more fields and returns the value of True and False.

You can read the whole article on the Validation Rule in Salesforce.

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 whenever users creating records from the Screen Flow component entered incorrect data and displayed error messages for that particular field.

How to Add Validation to Screen Flow in Salesforce

We can add validation to the screen flow in Salesforce using the above scenario and the following steps.

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

See also  Conditional Visibility in Salesforce Flows

Then, click on the New Flow button to create a new flow.

2. Here, when the user enters incorrect details in the fields, the field should throw an error. To do that, create a flow with the Screen Flow component. Click on it and then click on the Create button.

3. Now, we have to add Fields to the screen. 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 the Canvas.

Then, enter the Label and API Name to the Screen component.

Create Validation on Screen Flow in Salesforce

4. Now, we need to create some fields. Here, I have created a Text field with the Label City, and the API Name will automatically populate. Check the Required checkbox.

How to Add Validation to Screen Flow in Salesforce

5. Then we have to validate this field; for that, as you scroll down, you will see in the first image the Validate Input option. As you click on Validate Input, you will see Error Message, where we can enter what message we want to display over the screen.

6. Then, in the second image, we need to enter customer logic to validate that field. For that, we have the Formula option. Here, in this Text field, I want the user’s input to be only alphabetic. For that, we have the REGEX function.

Here, I have entered the formula for the City Text field: REGEX { {!City}, “[a-zA-Z]*$”}.

How to use Validation to Screen Flow in Salesforce

7. Then I added one more Phone field. Enter Label and API Name, and here we have the Pattern option where we can define the numbering pattern.

See also  How to Bypass Validation Rules Using Salesforce Flow

In the pattern field, I have entered: ^{[\d](10,15)}. Using this pattern, we can force the user to enter a phone no between 10 and 15 Digits.

Use Validation to Screen Flow in Salesforce

8. After setting up all labels and conditions, click the Save button to save the flow. For that, we need to enter the Flow Label. Here, I have entered the validation in the screen flow; the API Name will automatically populate as we click the text box. The Description is optional; we can introduce our flow Shortly.

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 use Validation on Screen Flow in Salesforce

8. As you click on the Debug button, you will see the Screen flow with fields that we created in the Screen Component. Here, we will check our validation. For the City field, we have validated it with only alphabetic values.

Here, we have also included the Numerical value, and when you click on the Finish button, you can see that the Error Message that we entered in the Screen component has occurred.

Use Validation on Screen Flow in Salesforce

9. Now, let’s remove the Numerical value, save the city text field only in the alphabetical value, and save the changes. Click on the Finish button.

How to Create Validation to Screen Flow in Salesforce

10. As you click on the Finish button, you will see the All Done Message, which means our flow has been debugged successfully. Now, you can Activate the flow.

How to Create Validation on Screen Flow in Salesforce

This is how we can add validation on the Screen Component in the Salesforce Flow.

See also  How to Send Custom Notification using Flow in Salesforce

Conclusion

I hope you have an idea about what the validation rule is in Salesforce. We also have seen how to add validation to Screen Flow in Salesforce with real-time scenarios and step-by-step explanations.

You may like to read: