Error Handling For Screen Flows

Screen Flows are a versatile user-friendly automation tool that can serve a user's varied needs. They are also quite administrator friendly because most screen flows of basic to medium complexity can be built solely by admins without the need for using helper apex code.

An important thing to remember when creating/updating a screen flow is its User Interface element. Any Screen flow should be designed to be user friendly, have at least the same or better user experience as the default Salesforce lightning experience, as well as handle problems/errors gracefully.

Example Screen Flow with no Error handling

The Fault Path

One of the most common Flow provision that admins and developers often overlook is the ability to add a Fault path to any action element. A Fault Path is the route that the Flow execution will take if and only if the action element where the fault path is connected from has an exception. In code terminology, it behaves exactly like the catch statement of a try/catch block.

Each Action element within a Flow can have at most one Fault Path. However, any element on any Fault Path can be routed to as the Fault Path from any number of distinct Action elements within the flow.

Fault Path Design Patterns

Usually, because people want to perform multiple automation tasks if an error occurs at runtime, a Fault route can be created that executes multiple automation sequences. Consider some or all of the following suggestions while configuring fault paths.

  • Present the exception to the running user in a friendly format.
  • Optionally, send an email, or post to the chatter feed of an active Salesforce administrator.
  • If using a mature Salesforce delivery model, and/or CI/CD, automatically create a bug in the project management system.
  • Place the entire Fault Path route in a separate sub-flow that can be used multiple times within the same flow or different flows.

Default Screen Flow User Interface when an Exception occurs

Example Scenario

In this example, we have a basic screen flow intended for an Account record page that provides the capability of updating an account's billing address. To mimic a validation exception, we have a validation rule on the Account object that prevents the record from being saved to the database if the billing country does not equal “US”. After configuring a sample Fault Path similar to the one in the last screenshot, the user running the Flow will be presented with a friendlier error message, as well as an active administrator will receive an email notification about the exception.

Adding a Fault Path to Lightning Flow

Within a Flow with Auto-Layout

  1. Make sure that the Action where Fault Path is being added does not have a Fault Path already.
  2. Click on the Action shape where the Fault Path has to be added.
  3. Click on the “Add Fault Path” option in the pop-up menu.
  4. Handle the fault (exception) gracefully by calling a sub-flow, or adding/connecting to existing Fault Route elements.

Within a Flow with Free-form Layout

  1. Make sure that the Action where Fault Path is being added does not have an existing Fault Path.
  2. Verify that the element where the Fault Path is being added already has a regular non-Fault route.
  3. Connect the Element to the first element where the Fault Route should begin.
  4. Handle the fault (exception) gracefully.

Example Screen Flow with a Fault Path error handler

Comments