Sub topic 2
Debugging a Flow in Flow Builder
This chapter assumes you can build a basic flow: create one, add elements, and use variables. It also assumes you know Salesforce objects, fields, and records, and that you have a sandbox or Developer Edition org. The Debug button in Flow Builder runs your flow and shows what happened at each element. You can use it before you activate a flow.
What the debugger does
Debug mode runs a real interview of the flow you have open. An interview is one execution of a flow. The debugger records each element the interview visits, the values of variables as they change, and the outcome of decisions, loops, and data operations.
By default, debug runs save changes to the database. Rollback mode is a debug option that undoes those changes. It is covered in the next chapter. Until you have read that chapter, run debugging only in a sandbox or Developer Edition org.
The debugger works for several flow types, but how you start it depends on the type:
- Screen flows run in a debug window where you fill in the screens.
- Autolaunched flows run with the input values you provide.
- Record-triggered flows ask for a record to use as the triggering record.
Running your first debug session
- Open the flow in Flow Builder.
- Click Debug in the top right of the canvas.
- Set any inputs the flow needs. For a record-triggered flow, pick the record that stands in for
$Record. - Click Run.
The debug panel opens and lists the elements the interview executed, in order. The canvas highlights the path taken. Elements that were never reached stay unhighlighted, so you can see at a glance which branch ran.
Reading the results
Each entry in the debug panel is an element. Expand an entry to see its details. The details depend on the element type.
| Element | What to check |
|---|---|
| Decision | Which outcome was chosen, and the values compared against each condition |
| Get Records | The filter used, and the records or field values returned |
| Assignment | The variable, the operator, and the value after the assignment |
| Loop | The current item and the loop position on each pass |
| Create, Update, Delete Records | The values written, or the error returned |
If an element fails, the panel shows an error message. It also shows the element where the interview stopped. This is the element to investigate first.
Work from the first wrong value
A failure often appears several elements after its cause. A Decision may take the wrong outcome because an earlier Get Records returned nothing. Read the panel from the top and look for the first value that differs from what you expected. Fix that element, then run again.
Common reasons for unexpected results
- A Get Records element found no record, so its variable is empty. Later elements then read a blank value.
- A Decision condition compares text with different capitalization or spacing than the data has.
- The wrong record was selected as the triggering record.
- A variable was never assigned, or was assigned after the element that needed it.
A worked example
Suppose a record-triggered flow on Opportunity creates a follow-up task when StageName changes to Closed Won. After saving, the flow creates no task.
- Click Debug and choose an Opportunity that is already Closed Won.
- Run the flow and open the Decision element in the panel.
- The panel shows the outcome "Default Outcome". The condition compares
{!$Record.StageName}toClosed Won. - Check the result. The record's stage matches. The flow may also require that the prior value was different, using
$Record__Prior. Because the record was already Closed Won, the "changed" condition fails.
The flow is correct, and the test record was wrong. Pick an Opportunity in an earlier stage, or edit the record in the debug inputs if the debugger allows it, and run again. Now the Decision takes the Closed Won outcome and the Create Records element runs.
Limits of the debugger
- It runs one interview. It does not show how the flow behaves when many records are processed together. Bulk testing is covered in a later chapter.
- Some elements, such as sending email or calling external services, may behave differently or be skipped in debug runs. Check the results for these elements.
- Debug runs use the permissions of the current user unless you choose otherwise. A flow that works for an administrator may fail for a standard user.
Exercise
A record-triggered flow's Decision element sends an interview down the Default Outcome even though the test record looks correct. What should you check in the debug panel first, and why?
Show answer
Open the Decision entry and compare the values shown for each condition with what you expected. Start with the first value that differs, such as a variable that an earlier Get Records element left empty, or a "changed" condition that cannot match because the test record already holds the final value. The cause of a wrong outcome is often earlier than the Decision itself.