Display Custom Error Messages for Record-Triggered Flows

Display Custom Error Messages for Record-Triggered Flows

Last Updated on August 4, 2023 by Rakesh Gupta

Big Idea or Enduring Question:

  • How can one present a customized error message(s) when record-triggered flow fails and prevent users from saving a record?

Objectives:

After reading this blog, you’ll be able to:

  • Understand the recently introduced Custom Error element.
  • Display a custom error message for record-triggered before-save flow.
  • Display a custom error message for record-triggered after-save flow.
  • Display the error message at the Top of the Page.
  • Display the error message below a specific field.
  • And much more

Business Use case

Benjamin Moore currently serves as a Salesforce Administrator at Gurukul On Cloud (GoC). He has created a record-triggered after-save flow to change related open opportunities to closed lost whenever an account goes out of business.

While the automation functions according to its design, there have been instances when Benjamin observed a failure in the after-save flow. This failure, caused by a validation rule, has led to increased support tickets for the IT team. To address this issue, Benjamin is considering the exploration of displaying a custom error message to the user if there is a failure in a record-triggered flow. He wants to present the following custom error messages when the flow has failed.

  1. Error message to show at the top of the Page
    1. {!$Flow.FaultMessage}
      Error in updating opportunities as lost due to lack of description. Here are the steps to correct this:
      1. Update the open opportunity referred by the partner.
      2. Update the description to include a reason.
  2. Error message to show below to Account Name
    1. If the problem persists after following all the steps mentioned above, please reach out to the IT team.

Prerequisite

Before we move further and discuss how to add a custom error message in the record-triggered flow, let’s take a step back and complete the Prerequisite.

Step 1: Create a Validation Rule on Opportunity

Create a validation rule on the opportunity that restricts sales reps from changing the status of a partner-referred opportunity to Closed Lost if the description field is not filled in. 

Step 2: Create a Custom Field – Out of Business (on Account)

  1. Click Setup.
  2. In the User Interface, clicks on Object Manager.
  3. Navigate to Account | Fields & Relationships and click on the Newbutton.
  4. Click on the Checkbox data type.
  5. Enter the Field LabeltheField Name will auto-populate. 
  6. Click on the Unchecked for the Default Value.
  7. Add a field on the Page Layout and grant field access to the desired profiles. 
  8. Click Save.

Step 3.1: 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 Record-Triggered Flow option, click on Create
    1. Object: Account
    2. Trigger the Flow When: A record is created or updated
    3. Set Entry Conditions: All Conditions Are Met (AND)
    4. Row 1: 
      1. Field: Out_of_Business__c
      2. Operator: Equals
      3. Value: {!$GlobalConstant.True}
    5. When to Run the Flow for Updated Records: Only when a record is updated to meet the condition requirements
    6. Optimize the Flow For: Action and Related Records
  5. Click the X at the top to save your changes.

Step 3.2: Adding an Update Records Element to Update Related Opportunities

The next step is to update the related open opportunities to close lost.

  1. On Flow Designer, click the +icon and select the Update Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. For How to Find Records to Update and Set Their Values select Update records related to the account record that triggered the flow
  4. Records Related to Account: {!$Record.Opportunities}
  5. Set Filter Conditions:

    1. Row 1:
      1. Field: IsClosed
      2. Operator: Equals
      3. Value: {!$GlobalConstant.False}
  6. Set Field Values for the Opportunity Records
    1. Row 1:
      1. Field: StageName
      2. Value: Closed Lost
  7. Click the X at the top to save your changes.

In the end, Benjamin’s Flow will look like the following screenshot:

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. API Version for Running the Flow: 59
  5. Interview LabelDisplay Custom Error {!$Flow.CurrentDateTime}
  6. Click Save.

Almost there! Once everything looks good, click the Activate button.

The flow generates the error message when the opportunity validation rule, which we created in step #1, prevents it.

Automation Champion Approach (I-do):

The previous error message is unclear, leading most business users to create a ticket for the IT team. However, with the Winter’24 release, it’s now possible to show a custom error message when using record-triggered flow, either for before-save or after-save flow.

If your Flow contains an element that interacts with the Salesforce database—such as an Update Records element or Create Records element – it can fail. You can modify the default behavior by adding fault paths to all elements that may fail.

  • Show customized error messages using Custom Error.
  • Send an email alert containing an error message to a group of people.

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

Let’s begin building this automation process.

Guided Practice (We-do):

There are 3 steps to solve Benjamin’s business requirement using Record-Triggered After-Save Flow and the newly introduced Custom Error element. We must:

  1. Clone Existing Flow
  2. Add Fault Path
  3. Add a Custom Error element to show custom error messages.

Step 1: Clone Existing Flow 

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows, then click on the Flow Name that will be modified. In this instance, click on the Display Custom Error flow, which we previously created as part of the prerequisite.
  4. Click the Save As button at the top right of the Flow builder.
  5. Click Save.

Step 2: Adding a Fault Path

It is recommended to configure the fault connectors in your flow so that you always receive an email when a flow fails and display a custom error message to users.

  1. On Flow Designer, click on the Update Records element.
  2. Select the Add Fault Path option from the list.

Step 3: Adding a Custom Error Element to Show Custom Error Messages

  1. Under the Fault node, select Custom Error element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Set Error Message 1 Details
    1. Where to Show the Error Message: In a window on a record page
    2. Error Message: (Limit 255 characters)

      1. {!$Flow.FaultMessage}
        Error in updating opportunities as lost due to lack of description. Here are the steps to correct this:
        1. Update the open opportunity referred by the partner.
        2. Update the description to include a reason.
  4. Click Add Error Message
  5. Set Error Message 2 Details
    1. Where to Show the Error Message: As an inline error on a field
      1. Select a field for the inline error message: Account Name
    2. Error Message:
      1. If the problem persists after following all the steps mentioned above, please reach out to the IT team.
  6. Click the X at the top to save your changes.

In the end, Benjamin’s Flow will look like the following screenshot:

Once everything looks good, Save the Flow and Activate it.

👉 Check out the video for step-by-step instructions.

Things to Remember
  1. The limit for the error message field is 255 characters.
  2. You’re only allowed to add one error message for a page.
  3. You’re only allowed to add one error message per field.
  4. it is not possible to use the link with your error message.
    1. escape parameter Indicates whether any HTML markup in the custom error message should be escaped (true) or not (false). This parameter is ignored in both Lightning Experience and the Salesforce mobile app, and the HTML is always escaped. The escape parameter only applies in Salesforce Classic. Read this article for more information.

Proof of Concept

Moving forward, if the flow we created, named Display Custom Error, fails at run time, then the custom error message that we defined within the fault path using Custom Error will be displayed.

Keep in mind you will still receive the flow error email from Salesforce.

Formative Assessment:

I want to hear from you!

What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? Feel free to share in the comments below.

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

 

One thought on “Display Custom Error Messages for Record-Triggered Flows

  1. I really enjoyed reading this blog. Your writing style is engaging, and the content is informative. Looking forward to more posts!

Leave a Reply

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