Try Catch in Salesforce Flow: How to Handle Errors Gracefully

Salesforce Flows are powerful tools for automating business processes, and implementing a try catch in Salesforce Flow is essential for handling the inevitable errors that can occur. Whether it’s a failed record update, a restricted picklist error, or missing required fields, these interruptions can derail both user experience and data integrity.

While Salesforce Flow doesn’t support the traditional programming construct of try-catch, there are structured ways to replicate this pattern. In this blog post, you’ll learn how to implement a try catch in Salesforce Flow using fault paths, error messages, platform events, and Apex exceptions.

Table of Contents


What is Try Catch in Salesforce Flow?

Unlike Apex, Salesforce Flow does not provide native try-catch blocks. However, you can simulate the same logic using fault paths.


Simulating Try-Catch in Flow: Key Concepts

Before we go deep into building the flow and handling flow exception, these concepts will help you understand the big picture.

1. Use Fault Connectors

Fault connectors help you capture any exception that occurs during element execution (e.g., Create/Update Records). You can route errors to display messages, create a case, log error in a custom object or send an email.

2. Capture Error Details

If you want to capture the details of the exception that happens in a flow. Use these Flow variables:

  • {$Flow.FaultMessage} – captures the error message
  • {$Flow.FaultRecordId} – identifies the record involved

It is similar to using the below code in apex. In apex we use e.getMessage() to the get the error text but in Flow we use a global variable {$Flow.FaultMessage}

catch (Exception e) {
    String errorMessage = e.getMessage();
    System.debug('Error Message: ' + errorMessage); // Output: Error Message: Attempt to divide by zero
}

3. Notify or Log Exception

Now that you know how to get details about the error in the Flow, its up to you how you want to track or notify System Admins about this error.

You can either log the error details in a Custom Object, notify users via Email, send details via Platform Events.


Understanding via a Use-Case – Job Application Management

To better understand the complete process of exception handling we are going to work on a usecase, which you should do a hands on in parallel. This will give you a better insights also confidence once you have completed the exercise.

Job Application Management is a common business process where recruiters manage job postings, candidate profiles, and applications. In this system, each job listing can receive multiple applications from candidates, and each application tracks the candidate’s progress through stages like Applied, Interviewing, or Hired. Ensuring data integrity—such as preventing applications to closed jobs or exceeding the number of openings—is crucial

Data Model Overview

We have three custom objects:

  1. Job__c
    • Title__c (Text, Required)
    • Openings__c (Number, Required, must be ≥ 1)
    • Status__c (Picklist: Open, Closed)
  2. Candidate__c
    • Name (Standard)
    • Email__c (Email, Unique, Required)
    • Phone__c (Phone)
  3. Job_Application__c (junction object between Job and Candidate)
    • Candidate__c (Lookup to Candidate__c, Required)
    • Job__c (Lookup to Job__c, Required)
    • Application_Date__c (Date, Required)
    • Status__c (Picklist: Applied, Interviewing, Rejected, Hired)

🔗 Relationships

  • Candidate can apply to multiple Jobs.
  • Job can have multiple Candidates applying.
  • The Job_Application__c object links them together.

Constrain

  • No Job Application can submitted for a Closed Job
  • A job can only accept Applications that is mentioned in Openings__c 

Note: We are going to use this use-case throughout our Flow learning series, so that your keep learning different things around flow and also build a complete use-case on Flow.

Handling exception in Screen Flow

In this scenario a recruiter submits a Job Application by assigning a Candidate to a Job. But she didn’t realise that the Job she is submitting the application for is actually closed. In this scenario the validation rule will fire and cause an exception in the flow.

Without a fault path : Flow structure without the Fault Exception

Flow without a fault path
Flow without a fault path

Error rendered to the user without a fault path

Unhandled error message breaking the flow execution
Unhandled error message breaking the flow execution

In case where there is no exception handling mechanism is placed in a flow, it will throw a generic message in the screen like the above screenshot.

With fault path: Flow with a fault path set

Adding Fault Path in Flow and screen element to show the message
Adding Fault Path in Flow and screen element to show the message

This is how we handle the exception and render a meaningful information to the user in the UI.

Custom Message showing in Screen elemtn of the flow during exception
Custom Message showing in Screen elemtn of the flow during exception

With a proper exception handling, we can gracefully handle the exception and be able to show a custom message or a fallback mechanism. This is a good experience where the target audience is non technical and coveys the message clearly.

Logging Flow Exceptions for debugging/ investigation

In the above example, we were able to handle the exception and show a custom message in the Fault path of the Flow. But it’s half the purpose solved if the System Admin is not aware of any functionality break.

Will it not be nice if the System Admins are notified via an email or we can capture these exception, their origin and other details for in depth analysis.

We are going to update our flow now to include different mechanisms to notify and analyze the Flow error.

  1. Sending Email
  2. Capturing Exception details in the Custom Log Object.
  3. Sending Platform Events to notify about the exception.

Sending Details about the Flow exception over Email

In order to notify System Admins about an error you can add a Send Email element in the fault connection of the Flow.

Send Email element configuration in Flow Fault Handle.
Send Email element configuration in Flow Fault Handle.
Screen shot of how email received from Flow
Screen shot of how email received from Flow

Capturing Exception details in the Custom Log Object

To capture details of the exception for further analysis, we are going to create a custom object with these fields.

Object Name: Exception Log

Field details:

Field API NameField LabelData TypeDescription
Source__cSourcePicklistValues: Flow, Apex
Exception_Type__cException TypeText (255)Type of exception (e.g., NullPointerException, DmlException)
Exception_Message__cException MessageLong Text AreaThe actual error message or stack trace
Context_Info__cContext InfoLong Text AreaAdditional context like input variables, record data, etc.
Related_Record_Id__cRelated Record IDText (18)ID of the record being processed when the error occurred
User_Id__cUserLookup(User)The user who triggered the process (if applicable)
Timestamp__cTimestampDate/TimeWhen the error occurred
Source_Name__cSource NameText (255)Name of the flow (if applicable)
Apex_Class__cApex ClassText (255)Name of the Apex class (if applicable)
Method_Name__cMethod NameText (255)Name of the method (if applicable)
Handled__cHandledCheckboxIndicates whether the error has been reviewed or resolved
Severity__cSeverityPicklistValues: Low, Medium, High, Critical
Notes__cNotesLong Text AreaAny extra notes or follow-up actions

Now we will update our fault path in the flow to create a record in the Exception custom object.

Flow configuration showing populating fields of custom Exception Object.

Flow Configuration creating a new custom Exception record
Flow Configuration creating a new custom Exception record

Exception from the Flow captured in Custom Exception Object

Custom Exception record created with details captured
Custom Exception record created with details captured

Sending Platform Events to notify about the exception

In order to fire a Platform Event from a flow, we first need to first create a new Platform Event Object.

From the Setup navigate to Platform Events. The do the below configuration on Platform Events.

Next, we will update out Flow to populate the details in the Platform Event object we created above.

Creating / Publishing Platform Event in Flow
Creating / Publishing Platform Event in Flow

So, now when an exception occurs a new Platform Event record is created and published. The subscriber of the platform event can consume these details and take further action.

The Platform Event can be subscribed within Salesforce or external systems via the Streaming API.


Best Practices for Try-Catch in Flows

  • Always plan for graceful failure—don’t leave users in the dark.
  • In the above example we have hardcoded values just for demo, but in real life scenarios use Custom Labels, Variables inside the Flow.
  • Log detailed error information for admins to review.
  • Use screen flows for interactive error messages and record-triggered flows for backend error logging.
  • Combine fault paths, email alerts, platform events, and custom Apex for robust error strategies.

Frequently Asked Questions

  1. How to add fault path in salesforce flow ?
Add Fault path in salesforce flow
Add Fault path in salesforce flow

In order to add a fault path in a flow, hover over any element in the flow which deals with Data (Example: Create, Update, Delete Records..) or element which performs any action like Send Email etc.

Then click on the 3 dots to to get more options, there you can see the option to Add Fault path from that element.

2. Can we follow these steps for error handling in record-triggered flow salesforce ?

You can follow the same steps for record-triggered flows or any flows running in the background. Except there is no need for a screen element to show custom message as its running in the background. But this blog will give you basic idea on different ways to handle exception in flows salesforce.

More Resources

How to Use Dynamic Custom Labels in FLOW


Conclusion

While there’s no built-in try catch in Salesforce Flow, you can confidently simulate it using fault connectors, platform events, and custom Apex code. These techniques ensure that your flows are resilient, user-friendly, and enterprise-ready.

👥 Was this helpful?
Share this post with your Salesforce network on Linkedin or Twitter
💬 Have questions or ideas? Leave a comment below!
📬 Want more tips like this? Subscribe for future updates.

2 Comments