Sub topic 6
Tracing flow execution with debug logs
This chapter assumes you can build a flow, run it in the Flow Builder debugger, and read the basic transaction and governor limit rules covered earlier. Debug logs are the tool to use when a flow fails outside the builder. That includes runs triggered by a real record save, runs by another user, and runs that combine a flow with Apex or other automation.
What a debug log gives you
The Flow Builder debugger runs one interview in isolation. A debug log records everything in a real transaction: the flow, any Apex triggers, validation rules, and the limits used. It shows the order in which these ran, which the builder cannot show.
A debug log is a text record of the events in one transaction. You choose which users are traced and how much detail is recorded.
Capture a log
- Open Setup and search for Debug Logs.
- Click New under User Trace Flags and select the user whose actions trigger the flow. For an automated process, this is usually the user who saves the record.
- Pick a start and expiration time. A trace flag can last at most 24 hours.
- Create or select a debug level. Set the Workflow category to
FINERor higher so flow events appear. Keep other categories low to avoid noise. - Reproduce the problem, then refresh the Debug Logs page and open the newest log.
Read the flow events
Flow events in a log begin with FLOW_. Search the log for that prefix first. The most useful events are listed below.
| Event | What it tells you |
|---|---|
| `FLOW_START_INTERVIEWS_BEGIN` | A batch of interviews started. The count shows how many records were processed together. |
| `FLOW_ELEMENT_BEGIN` and `FLOW_ELEMENT_END` | An element started and finished. The element type and API name are included. |
| `FLOW_ASSIGNMENT_DETAIL` | A variable received a value. |
| `FLOW_RULE_DETAIL` | The result of a decision outcome, `true` or `false`. |
| `FLOW_ELEMENT_ERROR` and `FLOW_ELEMENT_FAULT` | An element failed, or its fault path ran. |
| `FLOW_BULK_ELEMENT_BEGIN` | An element processed several interviews in one bulk operation. |
The next excerpt is simplified and shows the pattern of a failure:
CODE_UNIT_STARTED|[EXTERNAL]|Flow:Opportunity
FLOW_START_INTERVIEWS_BEGIN|1
FLOW_ELEMENT_BEGIN|Decision|Is_Closed_Won
FLOW_RULE_DETAIL|Is_Closed_Won|true
FLOW_ELEMENT_BEGIN|RecordCreate|Create_Follow_Up_Task
DML_BEGIN|[EXTERNAL]|Op:Insert|Type:Task|Rows:1
FLOW_ELEMENT_ERROR|REQUIRED_FIELD_MISSING: Required fields are missing: [Subject]
FLOW_ELEMENT_END|RecordCreate|Create_Follow_Up_TaskRead it from the bottom. The error names the element (Create_Follow_Up_Task), and the lines above show the path that led to it. The decision returned true, so the create ran, and the task had no subject.
Trace a failure step by step
- Search the log for
FLOW_ELEMENT_ERROR. If you find nothing, search forEXCEPTION_THROWNandFATAL_ERROR. The failure may come from Apex or a validation rule, not the flow. - Check the code unit lines. Several
CODE_UNIT_STARTEDentries show which automation ran and in what order. - Read backwards from the error to the last
FLOW_RULE_DETAILorFLOW_ASSIGNMENT_DETAIL. These show the values that led to the failure. - Confirm the error type. Errors such as
REQUIRED_FIELD_MISSINGorFIELD_CUSTOM_VALIDATION_EXCEPTIONare data problems. Errors containingToo many SOQL queries: 101are limit problems.
Check limits
For limit problems, find the limit summary near the end of the log. The CUMULATIVE_LIMIT_USAGE section lists SOQL queries, DML statements, and CPU time against their maximums. If a count is near its maximum, look for repeated SOQL_EXECUTE_BEGIN or DML_BEGIN lines between FLOW_ELEMENT_BEGIN events for the same element. Repetition means a query or DML sits inside a loop.
Common mistakes
- The trace flag covers the wrong user. Scheduled and asynchronous flows run as other users, so trace the right one.
- The Workflow category is too low, so no flow events are recorded.
- The trace flag expired before the failure happened.
- You assume the flow is at fault. Always check the other code units in the same transaction.
Exercise
A record-triggered flow fails with "Too many SOQL queries: 101" when 200 records are saved together. What do you search for in the debug log to confirm a query inside a loop, and what is the fix?
Show answer
Search for repeated SOQLEXECUTEBEGIN lines that occur between the FLOWELEMENTBEGIN entries of one Get Records element, and check the SOQL count in CUMULATIVELIMITUSAGE. Repetition shows that the element runs once per record. The fix is to move the Get Records element outside the loop, collect the needed records once, and use a collection variable inside the loop.