Skip to main content

Error handling in Salesforce Lightning Flow: How to Set Up Custom Error Messages and Improve Debugging

About Us
Published by a.bosak
30 October 2024
43

Have you ever felt like a detective at work?


Imagine: you add new functionality to your project – and suddenly, one of the flows "dies", everything rolls back, and users are greeted with a daunting error on their screens, the cause of which takes a long time to figure out.

After hours of digging through clues, logs, and debugging, you finally uncover the truth: one field needed for the flow to work was left blank, and this detail wasn’t accounted for. How much easier would it have been if you had planned for this from the start? In Apex methods, a try-catch block can handle the error and log a clear message in your system. But what about flows?

While preparing for my next Salesforce certification, Platform Developer II, I discovered a solution to this exact issue.

I’m talking about a new Salesforce feature – Custom Errors in Flow, introduced in the Winter 2024 release. Now we can set up custom error messages in critical spots to make each step transparent and predictable.

What are Custom Errors and How to Use Them

Custom Errors in Flow let you add user-defined error messages at points where things might go wrong. When designing a flow, it’s essential to identify these potentially risky points and add error handlers there. For example, using a Custom Error in a "Decision" element makes it easy to show an error message immediately if a required field is empty. Custom Errors can be set to display on the record page or directly next to a specific field, helping users quickly understand the issue.



 

This way, users receive an error message if they try to save a record manually.

What if the Record-Triggered Flow is Initiated by Apex?

This scenario is also covered. If a flow is triggered by a record created or updated from Apex, a Custom Error will throw an exception and halt the flow if conditions for the error are met. The error message will appear in the logs or the API response, and you can catch it in a catch block if it’s critical to your logic.

 

Are there any downsides?

The benefits of custom error handling are clear:

  • Quick problem identification: no need to search the entire system, as the error pinpoints the issue in the flow.
  • Improved logging: custom descriptions make it immediately clear what went wrong.

However, there are some drawbacks:

  • Potential debugging complexity: frequent errors can overload the system.

Configuration time: thoughtful setup and testing are needed, especially in complex legacy projects.


Lana Moroz
image
Question to the expert
image

We have available resources to start working on your project within 5 business days

1 UX Designer

image

1 Admin

image

2 QA engineers

image

1 Consultant

image