Sub topic 12
Fault Paths and Custom Errors
This chapter assumes you know Flow Builder elements (Get Records, Create Records, Update Records, Decision), what a database transaction is, and the difference between before-save and after-save flows from earlier chapters.
Why faults matter in record-triggered flows
A record-triggered flow runs inside the same transaction as the save that started it. If an element fails and nothing handles the failure, the flow throws an unhandled error. Salesforce rolls back the whole transaction, so the user's original save fails too. The user sees a generic flow error message, and admins get a failure email.
You have two tools to control this:
- A fault path catches a failure in a data element and lets you decide what happens next.
- A custom error deliberately stops the save with a message you write.
Fault paths
A fault path is a connector that runs when an element fails. You add it by selecting the element's connector options and choosing Fault. Fault paths are available on elements that can fail at run time, such as Create Records, Update Records, Delete Records, and Action elements.
Before-save flows are more limited. They can't run most actions, and an Assignment element has no fault connector. In practice, fault paths matter most in after-save flows, where you create or update related records.
When a fault path runs, the flow stores the error text in the global variable {!$Flow.FaultMessage}. Typical fault handling steps are:
- Log the failure, for example by creating a custom
Flow_Error_Log__crecord. - Notify someone, for example with an email alert.
- End the flow, so the original save can still succeed.
Flow: Opportunity - Create Follow-up Task (after-save)
Create Records element (object: Task)
Fault connector -> Create Records element (object: Flow_Error_Log__c)
Flow_Name__c: Opportunity - Create Follow-up Task
Record_Id__c: {!$Record.Id}
Message__c: {!$Flow.FaultMessage}What a fault path does to the transaction
Once a fault path handles an error, the flow continues. The failed element's own changes are not saved, but the rest of the transaction is not automatically rolled back. This is useful, but it has a consequence: if earlier elements already made changes, they stay.
Logging the error also writes a record inside the same transaction. If something later in the transaction causes a rollback, your log record is rolled back too. For critical logging, use an approach that survives rollback, such as publishing a platform event.
Custom errors
Sometimes you want the save to fail. A flow can enforce a business rule that a validation rule can't express easily, such as checking related records.
The Custom Error element stops the transaction and shows a message you write. It is available in record-triggered flows, in both before-save and after-save. You place it on the path where the rule is broken, usually after a Decision element.
Flow: Opportunity - Block Close Without Products (after-save)
Entry condition: {!$Record.StageName} = "Closed Won"
Get Records (Opportunity Line Items where OpportunityId = {!$Record.Id})
Decision: Any line items found?
No -> Custom Error element
Message: Add at least one product before closing this deal.
Yes -> EndThe Custom Error element can show the message at the top of the page, or next to a specific field if you choose a field. All changes in the transaction are rolled back, including the user's own edit.
Fault path or custom error?
| Situation | Use |
|---|---|
| A non-essential step, like creating a follow-up task, might fail | Fault path that logs and continues |
| A business rule is broken and the save must not happen | Custom Error element |
| A required step failed and partial results would be wrong | Fault path that leads to a Custom Error element |
Common mistakes
- Leaving data elements without fault paths. One bad related record can block a user's save.
- Showing
{!$Flow.FaultMessage}to end users. It often contains technical detail. Log it, and show a clear message of your own. - Assuming a fault path rolls back earlier work. It doesn't. Earlier elements' changes remain unless you stop the transaction with a Custom Error.
Exercise
An after-save flow creates a Task when an Opportunity closes. The Task insert sometimes fails because of a validation rule on Task. You want the Opportunity save to succeed anyway, and you want admins to see what happened. What do you build?
Show answer
Connect a fault path from the Create Records (Task) element to a Create Records element that writes a log record (for example FlowErrorLog__c) with the Opportunity Id and {!$Flow.FaultMessage}, then end the flow. The Opportunity save then succeeds. Someone must also review the log, or send a notification, so the failure is not silent.
Exercise
A manager wants to stop reps from setting an Opportunity to Closed Won when it has no products. Which element do you use, and what happens to the rep's edit?
Show answer
Use a Get Records element for the line items, a Decision element to check whether any exist, and a Custom Error element on the "none found" path with a clear message. The transaction rolls back, so the rep's edit is not saved and they see the message.