Sub topic 5
Handling errors with fault paths
This chapter assumes you can build record-triggered and screen flows, use variables and Get Records and Update Records elements, and run a debug session in Flow Builder. You should also know how a flow shares a transaction with the save that triggered it. Work in a sandbox or Developer Edition org, because several exercises deliberately make flows fail.
What a fault path is
A fault path is an alternate connector that leaves an element and runs only if that element fails. In Flow Builder it appears as a red connector labeled Fault. The normal connector is the success path, and the fault connector is the failure path.
Without a fault path, an element that fails stops the whole flow interview. What the user sees depends on the flow type:
- In a screen flow, the user sees a generic "An unhandled fault has occurred in this flow" message.
- In a record-triggered flow, the triggering save fails and the transaction rolls back. The user sees an error on the record page.
- In an autolaunched flow started from Apex, the failure surfaces as an exception in the calling code.
In all three cases, Salesforce also sends a flow error email, which a later chapter covers.
A fault path changes this. You decide what happens next: log the error, notify someone, show a friendly message, or stop the transaction deliberately. The flow no longer fails by default. It fails only when you tell it to.
Where fault paths are available
Only elements that interact with data or the outside world can fail at run time, so only those elements offer a fault connector.
| Element | Fault path available | Typical cause of failure |
|---|---|---|
| Get Records | Yes | Query problems, field access errors |
| Create Records | Yes | Missing required field, validation rule, duplicate rule |
| Update Records | Yes | Validation rule, Apex trigger error, locked record |
| Delete Records | Yes | Record is referenced elsewhere, no delete permission |
| Action (Apex, email, and so on) | Yes | Exception in the invoked action |
| Subflow | Yes | Any unhandled failure inside the child flow |
| Decision, Assignment, Loop, Screen | No | These do not fail in this way |
An Assignment element can still produce a bad value, such as a null, that makes a later element fail. When that happens, the fault path belongs on the later element.
Adding a fault path
- Select the element in the canvas, for example a Create Records element.
- Hover over the element and drag from its connector handle to the next element. If the element supports faults, Builder asks whether the connector is Fault or the normal path.
- Choose Fault. A red connector appears.
- Build the handling logic on that branch and end it with a clear outcome.
Each element needs its own fault connector, but several elements can point to the same handler. That works well when the handling is generic, such as "log the message and email an admin." Use separate handlers when the right response differs per element. A failed lookup might need a default value, while a failed insert might need a rollback.
Capturing the error with $Flow.FaultMessage
$Flow.FaultMessage is a global variable that holds the text of the most recent error. It has a value only inside a fault path, so reading it on the success path gives you nothing useful.
The text is often the most useful debugging detail you get. It usually names the failing rule or field, for example "FIELDCUSTOMVALIDATION_EXCEPTION: Close date cannot be in the past."
Here is body text for a Send Email action or a log record on the fault branch:
An error occurred in the flow: {!$Flow.FaultMessage}
Flow: {!$Flow.CurrentDateTime}
Record Id: {!$Record.Id}$Record.Id works only in record-triggered flows. In a screen flow or autolaunched flow, pass the record Id in through a variable and reference that variable instead. $Flow.CurrentDateTime gives the time of the failure, which helps you match it against debug logs.
Other useful context to capture alongside the message:
- The flow's API name. Hard-code it in a text variable, because there is no built-in global for it in the fault path.
- The name of the element that failed. Hard-code this in each handler or in a separate text variable assigned just before the fault.
- The running user, using
{!$User.Username}. - The Id of the record being processed.
Common handling patterns
The right pattern depends on who needs to know and whether the transaction should continue.
Log and continue
Create a record in a custom log object, such as Flow_Error_Log__c, with fields for the message, flow name, element name, and related record Id. Then let the flow finish normally. This suits non-critical work, such as a notification task that failed to insert.
Be aware of one effect. Once the fault path handles the error, the flow completes without raising an error, so the triggering save succeeds. The log record is also saved. This is the main reason to log: a handled error leaves no other trace unless you create one.
Notify
Use a Send Email action on the fault branch to email an administrator or a shared mailbox. The email body can use the text from the previous section. Keep two limits in mind. Emails sent from flows count against daily email limits, and a flow that fails often can send a flood. For high-volume flows, prefer a log record plus a report or scheduled summary.
Tell the user
In a screen flow, route the fault path to a Screen element that shows a plain-language message. You can include {!$Flow.FaultMessage} when the audience is technical, but a business user usually needs something simpler, such as "We couldn't save your changes. Contact your administrator and give them this reference number." Pair the screen with a log record so support can find the details.
Stop the save deliberately
In a record-triggered flow, you can end the fault path with a Custom Error element. It stops the transaction and shows your message on the record. Use it when failure should block the save but you want a readable message instead of a raw system error. A fault path that ends quietly lets the save proceed, which is wrong when the failed step was essential.
Roll back
If earlier elements in the same transaction already made changes, you may want to undo them. Where your flow type supports it, the Roll Back Records element reverses the data changes the interview has made so far. Check availability for your flow type before relying on it. An alternative is to end in a Custom Error, which cancels the whole transaction.
How fault paths interact with transactions
A fault path changes what gets rolled back, so decide this on purpose.
- When an element fails and no fault path exists, the transaction rolls back. Everything the flow did in that transaction is undone, along with the triggering save in a record-triggered flow.
- When an element fails and a fault path handles it, the failed element's own change is not saved. Records the flow already saved earlier in the same transaction stay in place unless you roll them back. If the flow then finishes normally, the transaction commits.
That second point catches many teams. A flow that creates a parent record, fails creating the child, and logs the error can leave an orphaned parent. Decide whether partial success is acceptable. If it isn't, finish the fault path with Custom Error or Roll Back Records.
A fault path also does not protect against everything. Governor limit errors, such as too many SOQL queries or too many DML statements, end the transaction and cannot be handled with a fault path. Fix those by removing queries and DML from loops, as covered earlier in this tutorial. Do not rely on fault paths for them.
Fault paths in a bulk transaction
Record-triggered flows run once per batch of up to 200 records, not once per record. Create, Update, and Delete elements that receive a collection run as a single operation. If one record in the collection fails, the element fails as a whole, and the fault path runs once for the whole batch.
This has two consequences. First, $Flow.FaultMessage describes the failure, and it may not tell you which record caused it. Capture the record Ids you can, or log the collection size. Second, a single bad record in a batch can block the other 199 changes from being saved by that element. This is another reason to test flows with bulk data, which a later chapter covers.
Debugging a fault path in Flow Builder
You can test the failure branch without waiting for production data to fail.
- Open the flow and click Debug.
- Choose input values that will make the target element fail. For example, leave a required field empty, or use a record that violates a validation rule.
- Run the debug session. Builder highlights the path taken. The fault connector and the handler elements should light up.
- Open the details for the failed element. Builder shows the error message that
$Flow.FaultMessagewill contain. - Turn on Run in rollback mode if you do not want the log record and other changes saved while you test.
Debug runs execute for real unless rollback mode is on. A fault handler that sends an email or creates a log record will do so during the debug session. Rollback mode undoes the database changes, but it does not unsend emails. Point test emails at your own address, or disable the email while you debug.
Common mistakes
- No fault path on DML elements. The user gets a generic message and you get an error email with little context.
- Fault path ends silently. The flow looks successful while data is missing. Always log or notify.
- Handling the error but allowing a wrong save. If the failed step was required, finish with Custom Error.
- Reading
$Flow.FaultMessageoutside the fault path. It will be empty on the success path. - Hard-coding an admin email in many places. Use a custom label, a custom setting, or a single reusable subflow for error handling.
- Assuming fault paths catch limit errors. They do not.
A reusable error-handling subflow
A common design is a single autolaunched subflow, for example Log_Flow_Error, that every fault path calls. Its inputs are the error message, flow name, element name, and record Id. It creates the log record and optionally sends an email. The benefits are one place to change the logging format, consistent data for reports, and shorter parent flows.
Note that a subflow is itself an element that can fail. Keep the subflow small, and consider a fault path inside it that does nothing more than end, so a logging failure does not hide the original error.
Exercise
A record-triggered flow creates a Task when an Opportunity closes. The Create Records element has a fault path that creates a log record and then ends. A validation rule on Task blocks the insert. What happens to the Opportunity save, and how would you change the flow if the task is mandatory?
Show answer
The Create Records element fails, the fault path runs, and the log record is created. The flow then ends normally, so the Opportunity save succeeds without a Task. The error is handled, so there is no rollback and no error shown to the user. If the task is mandatory, end the fault path with a Custom Error element (or use Roll Back Records where available) so the save is blocked and the user sees a message. Keep the log creation before the Custom Error only if the log should survive, but note that a Custom Error rolls back the whole transaction, including the log record. To keep a durable log, write it from a separate transaction, such as an asynchronous path.
Exercise
Why can you not use a fault path to catch "Too many SOQL queries: 101" in a flow, and what should you do instead?
Show answer
Governor limit errors end the transaction and cannot be handled by a fault path. The fix is to change the design: move Get Records, Create Records, Update Records, and Delete Records elements out of loops, collect values in a collection variable, and run one operation on the collection after the loop. Confirm the fix by testing with 200 records.