Getting Started with Salesforce Flow – Part 57 (Adding Validation to Flow Screen Components)

Getting Started with Salesforce Flow – Part 57 (Adding Validation to Flow Screen Components)

Last Updated on February 9, 2021 by Rakesh Gupta

Big Idea or Enduring Question:

How do you validate user input for Screen Flow Components? 

Input Validation in Salesforce Flow allows a system administrator to define custom logic and error messages to ensure data integrity. A Validation can contain a formula or expression that evaluates the data in one or more fields and returns a value of True or False. Validation also includes an error message that displays when the rule returns a value of Trueindicating that inaccurate data is being entered. 

In the past, I have written a few articles on Validation Rules and Salesforce Flow. Why not check them out while you are at it?! 

  1. Getting Started with Salesforce Flow – Part 21 (Validation Rule using a before-save Flow? Yes!)

Objectives:

After reading this article, you will be able to:

  • Add validation to check what a user enters in a flow screen component and display an error message to guide the user
  • Display colorful error message 
  • and much more 

Business Use Case

Steven Greene, a Lead System Administrator at Universal Containers (UC)received a requirement to create a Screen Flow with the following fields:

  1. City – Only alphabet characters (A-Z or a-z) are allowed 
  2. Phone – Minimum 10 and Maximum 15

Automation Champion Approach (I-do):

To solve the above business use case, will use Screen Flow.

Before discussing the solution, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes to go through the following Flow diagram and understand it.

Let’s begin building this automation process.

Guided Practice (We-do):

There are 4 steps to solve Steven’s business requirement using Screen Flow. We must:

  1. Salesforce Flow Steps: Define flow properties 
  2. Add a screen to capture the user’s input
  3. Add a Text component to store the city 
    1. Add input validation to validate user input 
  4. Add a Phone component to store the Mobile Number  
    1. Add input validation to validate user input 

Step 1: Salesforce Flow – Define Flow Properties   

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows then click on the New Flow.
  4. Select the Screen Flow option and click on Next and configure the flow as follows: 
    1. How do you want to start building: Freeform
  5. It will open the flow designer for you.

Step 2: Salesforce Flow – Add a Screen Element  

  1. Under Toolbox, select Elements. Drag and drop Screen onto the canvas. 
  2. Input the following information:
    1. Enter Label the API Name will auto-populate.
  3. Click Done

Step 3: Salesforce Flow – Add a Text Component to Store the City

  1. Under Input section on Screen Element. Drag and drop the Text component onto the screen. 
  2. Input the following information:
    1. Enter a name in the Label field; the API Name will auto-populate.
    2. Select Require checkbox.
  3. Click Done

Step 3.1: Salesforce Flow – Add Input Validation to Validate User Input – City

It’s time to add a validation check to verify that city only contains alphabet characters (A-Z or a-z). 

  1. Under the Text Component, expand the Validate input section. 
  2. Now we will define the values allowed for the component by entering a Boolean formula. 
  3. Input the following information:
    1. Error Message: Please input alphabet characters only
      1. Use Rich-Text editor to format error message 
    2. Formula: REGEX( City, “[a-zA-Z ]*$”)
  4. Click Done.

Step 4: Salesforce Flow – Add a Phone Component to Store the Mobile Number 

  1. Under Input section on Screen Element. Drag and drop the Phone component onto the screen. 
  2. Input the following information:
    1. Enter API Name.
    2. Field API Name: MobileNumber  
    3. Label: Mobile Number 
    4. Required: {!$GlobalConstant.True}
    5. Advanced > Revisted Screen Values: Use values from when the user last visited this screen 
  3. Click Done

Step 4.1: Salesforce Flow – Add Input Validation to Validate User Input – Mobile Number 

It’s time to add a validation check to verify the length of the mobile number. For this, we will use the regex in the Phone component.   

  1. Under the Phone Component, expand the Field Properties section. 
  2. Now we will use the regex to validate the length
    1. Pattern: ^[\d]{10,15}
  3. Click Done.

In the end, Steven’s Flow will look like the following screenshot (I turned on Auto-Layout) for this flow: 

Once everything looks good, perform the steps below: 

  1. Click Save.
  2. Enter Flow Label the API Name will auto-populate.
  3. Click Show Advanced.
  4. Type: Screen Flow
  5. API Version for Running the Flow: 51
  6. Interview Label: User Input Validation {!$Flow.CurrentDateTime}
  7. Click Save

Things to Remember:

  1. The formula expression must return a Boolean value (true or false).
  2. If the formula expression evaluates to true, the input is valid.
  3. If the formula expression evaluates to false, the error message is displayed to the user.
  4. If the user leaves the field blank and the field is not required, the flow doesn’t validate.
  5. If the user leaves the field blank and the field is required, the flow shows the default error message and not the custom error message.

Proof of Concept

Now flow will display an error message if the user doesn’t enter the data correctly.

Formative Assessment:

I want to hear from you!  

What did you learn from this post, is it relevant to you, and how will you modify the concepts taught in the post for your own business processes?  

Make a post and tag me on Twitter @automationchamp using #AutomationChampionFlow.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

7 thoughts on “Getting Started with Salesforce Flow – Part 57 (Adding Validation to Flow Screen Components)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.