Exception handling in flow

In this session, we will talk about how to handle exceptions/errors in Salesforce flow using fault connectors and the Platform events framework. Let learn about Exception handling in flow.

Handling & Logging

Let understand the different between Exception handling and Logging:

  • Exception Unexpected event occurred during your transaction execution
  • Exception Handling Deal with unexpected Exception
  • Exception Logging Store exception details for later analysis and troubleshooting

Let see how to handle exceptions in a Salesforce flow using fault connector, and what will be the transaction behavior after adding a fault connector to the flow.

Exception handling in flow Scenario 1

Suppose we have one flow which updating Account with contacts country. like below which invoked from process builder.

Exception handling in flow

Create Exception Scenario

Let try to add some exception with the help of validation rule. Let us add a validation rule under Account which makes Account Number mandatory on Account update.

Create Exception Scenario

Now if account number is missing on account record then our flow will fail. Now let see how we can handle this exception.

Handle & Log Exception – Exception Object

As a best practice, Lets try to log all exceptions in an Exception custom Object.

Handle & Log Exception – Exception Object

How to handle Exception in a flow?

To handle Exception, we need to add a fault connector to the record update operation as shown below.

What is Fault Connector?

Identifies which element to execute when the previous element results in an error

What is Fault Connector?

Let see what will happened after adding flow connector ?

Handle & Log Exception – Transaction Behavior

Handle & Log Exception – Transaction Behavior
  • Contact Creation is success
  • Account Country is not populated
  • Exception Record Got Created
  • Similar to try-catch in Apex

Handle & Log Exception – Throw Exception

What about if you want to fail the complete transaction ? But we have seen that we have a fault connector – transaction will be a success.

  • No standard Approach in Flow
  • Make use of Apex Throw exception
Handle & Log Exception – Throw Exception

In Apex classes you have an option to throw exception after catching and logging error details. So let us see if we can add that behavior to a flow. We can use the invocable Apex method, which can throw our flow exception.

Handle & Log Exception – Throw Exception

This issue can be solved by logging exception using Platform events

Exception Logging – Platform events

Exception Logging – Platform events

Platform events – Publish Behavior

Why we need PE & Exception Object?

PE does not provide:

  • Reporting
  • Querying
  • Formula fields for additional processing

Scenario 2) Screen flow – Exception Logging

If the Account type is Partner Account – Display a screen to enter additional details by user and based on entered values, decide Account Partnership level as Diamond, Gold or Silver

Screen flow – Exception Logging

Screenflow – Exception Logginig using FlowExecutionErrorEvent

  • FlowExecutionErrorEvent – Standard Platform event from Salesforce
  • Salesforce publish event to this when a screen flow fails
  • We can subscribe to this and log Exception

Comparison between Custom Platform event and FlowExecutionErrorEvent approach for Exception Logging

Exception handling in flow Video

Agenda :

  • Flows Use Cases
  • Exception Handling & Logging
  • Exception Object & Fault Connectors
  • Transaction Behavior
  • How Platform Events Helps
YouTube video

Thanks Meera Nair for sharing your knowledge with us.

Amit Chaudhary
Amit Chaudhary

Amit Chaudhary is Salesforce Application & System Architect and working on Salesforce Platform since 2010. He is Salesforce MVP since 2017 and have 17 Salesforce Certificates.

He is a active blogger and founder of Apex Hours.

Articles: 469

7 Comments

  1. GREAT….Very Helpful, thanks for sharing your knowledge.
    One small suggestion – it would be great if you can embed the code snippets instead of screen-shots.

  2. Hello Meera,
    Thanks for the youtube video.
    One question: For update record, we will have a collection variable to update. What if only 1 out of 10 records failed. I want to create exception record for only one record the failed one. Do you know how do we handle this in flows. Does the flow update/create record returns the same Database.SaveResult[] same as returned by Database.insert /update/upsert
    Or Its AllORNone = true for flows?
    Please throw some light on this if you can

    • Hi Raman – did you ever get an answer to your question? If 1 of many in a collection variable fails will the others succeed as is the case in Apex if using Database.insert and Database.SaveResult or is it All-or-none with Flow?

  3. Helpful video – in non-screen flows, is there a way to create a pop up notification under certain conditions?

  4. How can we add fault connectors in before save flows(Fast Update)? I don’t see any fault connectors for before save flows. How can we do exception handling for before save flows if we don’t have an option to create records?

Leave a Reply

Your email address will not be published. Required fields are marked *