Skip to content
Tutorials Center
My learning

Topics

Lesson 23 of 36 ยท Automation with Flow

Flow Errors, Debugging and Testing

Make Salesforce flows reliable: fault paths, error emails, the Debug tool, flow tests, the paused and failed interview list, and a checklist, with JavaScript stand-ins.

Every automation fails eventually: a required field is empty, a validation rule rejects an update, a user lacks access, a limit is hit. The difference between a professional flow and a fragile one is what happens next. A professional flow tells the user something useful, records what went wrong, and leaves the data consistent. This lesson covers fault paths, the Debug tool, flow tests and the places where Salesforce reports errors.

The Salesforce menus are described in words, and the demonstrations are labelled JavaScript stand-ins: nothing here shows real Salesforce output.

Fault paths

Elements that can fail (Get Records, Create, Update, Delete, Action, Subflow) can have a Fault connector. In Flow Builder, hover over the element, click the plus sign and choose Add Fault Path (in older UIs, an element shows a red Fault connector you drag to another element). If the element fails, the flow follows the fault path instead of stopping.

On the fault path you typically:

  1. Show a Screen (in a screen flow) with {!$Flow.FaultMessage} so the user sees the reason.
  2. Create a record in a custom Error Log object with the flow name, the record Id and the message.
  3. Send an email or post a notification to the admin team.
  4. End the flow (and, in a record-triggered flow, optionally use a Custom Error element, below, to stop the save).

{!$Flow.FaultMessage} holds the error text of the failure. Without any fault path, the flow stops with an unhandled error: the user sees a generic message and the admin who last modified the flow gets an email titled "Error Occurred During Flow ..." (the recipient can be changed in Process Automation Settings).

A Create or Update step that succeeded before the failure is rolled back for a record-triggered flow, because the whole transaction fails. In a screen flow, each transaction boundary behaves differently: a screen starts a new transaction after it is shown, so data saved before an earlier screen stays saved. Know where your transaction boundaries are.

Stopping a save with a Custom Error

Record-triggered flows can contain a Custom Error element. It stops the save and shows your message to the user, which makes it a flow-based alternative to a validation rule for conditions that need related data. Example: "You cannot close this case while it has open tasks." Use validation rules for simple checks on the record itself, and Custom Error when you need a Get Records first.

The Debug tool

Click Debug in Flow Builder and the tool runs the flow with values you provide.

  • For a record-triggered flow, choose a record to simulate, or enter field values. Options include Run flow as another user, Show details of what is in scope, Rollback mode (nothing is saved, the default) and Run the flow in rollback mode turned off for a real run.
  • For a screen flow, enter input variable values, then click through the screens.
  • Debug output lists each element in the order it ran, with the values of variables and the outcome of each Decision. Failed elements show the error message.

Use Rollback mode while testing so the changes do not stick. Be careful: if you turn it off, debug runs do change real data, send real emails and call real actions.

For a record-triggered flow in an after-save timing, Debug also helps spot a Decision that never matches because the entry condition and the Decision disagree. For a scheduled flow, debug lets you choose how many records to run.

Flow tests

Record-triggered flows can have Flow Tests, a lightweight automated test set (Test button in Flow Builder, in the Flow Tests area). A test defines:

  • the initial record (for create) or the updated values (for update),
  • assertions: for example, "the Task count is 1" or {!$Record.Priority} equals High.

Tests run in the same rollback manner as debug. You can run tests every time you edit the flow, before activation, so refactoring is safe. Keep a few tests for each important outcome, including an outcome that should do nothing.

Looking at runs and failures

  • Setup, Paused and Failed Flow Interviews lists paused interviews (waiting for time or a user) and failed ones, with the flow, the element and the error.
  • Process Automation Settings controls who receives unhandled error emails.
  • Debug logs (Setup, Debug Logs) record what ran for a user, down to each flow element, and are the tool of last resort for complex transactions.
  • Event Monitoring and the Flow Interview object let you report on flow runs if you have the licenses.
  • A Flow Error Log that you build yourself (custom object plus fault paths) gives your team a report and dashboard of failures. This is the cheapest and most useful monitoring.

A fault-path pattern with logging

flowchart TD
  A["Get Records: Account"] -->|"Success"| B["Update Records"]
  A -->|"Fault"| F["Create Records: Error Log"]
  B -->|"Success"| E["End"]
  B -->|"Fault"| F
  F --> N["Action: Email admin team"]
  N --> E2["End"]

Both data elements share one fault handler.

Stand-in: fault paths and an error log

This stand-in is not Salesforce. It runs a list of steps, and when one throws, it follows a fault handler that logs the error, just as a fault connector would.

JS Stand-in: fault path with an error log

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Stand-in: tests with assertions

JS Stand-in: a mini flow test runner

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Pre-activation checklist

  1. Fault path on every data element and action, with a clear message or log entry.
  2. Debug run for each Decision outcome, and for the default outcome.
  3. Flow tests for the important outcomes (record-triggered).
  4. Bulk test with 200 records.
  5. Test as a non-admin user with realistic permissions.
  6. Description, naming and entry conditions documented.
  7. A rollback plan: keep the previous version, and note how to deactivate quickly.

When a flow misbehaves in production, deactivate first, investigate second: activate the earlier version (or turn the flow off) to stop the damage, then reproduce the problem in a sandbox.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does {!$Flow.FaultMessage} contain?

    It holds the message from the failure, which you can show to users or log.
  2. 2. Why use Rollback mode in the Debug tool?

    Rollback mode undoes data changes from the test run.
  3. 3. Which element stops a record save and shows your own message?

    The Custom Error element in a record-triggered flow blocks the save with a message.
  4. 4. A flow breaks in production. What do you do first?

    Stop the damage first, then investigate safely.

Summary

  • Add a fault path to every element that can fail, and log or show the error message.
  • Custom Error blocks a save from a record-triggered flow when you need more than a validation rule.
  • Debug (in rollback mode) and Flow Tests give fast feedback; test with bulk data and as a normal user.
  • Check Paused and Failed Flow Interviews, error emails and your own error log object.

Next: Report types and report formats