Sub topic 6
Tracing flow execution with debug logs
The Flow Builder debugger shows one run of one flow. Debug logs show what the whole transaction did, including the flows, Apex, validation rules, and limit usage around it. Use them when a failure happens outside the builder, such as for a different user, a scheduled flow, or a record-triggered flow that fires as part of a larger save.
This chapter assumes you can build a flow with variables and elements, and that you know the basic Flow Builder debugger and fault paths from earlier chapters. You need a sandbox or Developer Edition org and a user who can open Setup.
What a debug log is
A debug log is a text record of what happened during one transaction for one traced user. It lists events in order, each with a timestamp, an event name, and details. The log has three parts that matter for flows:
- The executed events, such as
FLOW_START_INTERVIEWS_BEGINandFLOW_ELEMENT_BEGIN. - The data events, such as
DML_BEGINandSOQL_EXECUTE_BEGIN. - The limit summaries, such as
CUMULATIVE_LIMIT_USAGE, near the end.
A log has a size cap of 20 MB, and a user can keep logs only up to a total org-wide storage limit. When a log passes its cap, Salesforce truncates the oldest part of the log. If the event you need is missing, the log probably overflowed. Lower the log levels, as described below, and reproduce the problem again.
Setting up a trace
You start a trace in Setup. Open Debug Logs, then add a trace flag for a user. A trace flag has four settings:
| Setting | Meaning |
|---|---|
| Traced entity | The user (or automated process user) whose transactions are logged |
| Start and expiration date | The time window in which logging is active |
| Debug level | A named set of log categories and levels |
| Log type | User-based logging, which is the usual choice for flow work |
Choose the traced entity carefully. A log records the context user of the transaction. A record-triggered flow that runs after a user edits a record is logged under that user. A scheduled flow, or a flow started by a time-based action, runs as the Automated Process user, so you must trace that user instead. If you trace yourself and the failing run belongs to another user, no log appears.
Choosing a debug level
A debug level assigns a log level to each category. The levels run from NONE up through ERROR, WARN, INFO, DEBUG, FINE, FINER, and FINEST. Higher levels add detail and size. For flows, set these categories:
| Category | Suggested level | Why |
|---|---|---|
| Workflow | `FINER` | Flow and process events are logged here |
| Database | `INFO` | Shows SOQL and DML without too much volume |
| Apex Code | `DEBUG` | Shows Apex invoked by the flow and user debug statements |
| Validation | `INFO` | Shows validation rules that block a flow's DML |
| System | `DEBUG` | Includes limit summaries |
| All others | `NONE` or `WARN` | Keeps the log small |
Workflow at FINER is the setting that matters most. At lower levels you see flow start and finish events but not the element-by-element detail.
Run the failing action after the trace flag is active. Then open Debug Logs and find the new entry. You can also open the Developer Console and use Debug, then Open Execute Anonymous Window, if you want to trigger an update from Apex and read the log right away.
Reading flow events
Open a log in the Developer Console log viewer, or download it as text. Use the filter box to cut the noise. Typing FLOW_ leaves only flow events. Typing FLOW_ELEMENT leaves one line per element.
These are the events you will see most often:
| Event | What it tells you |
|---|---|
| `FLOW_START_INTERVIEWS_BEGIN` | A batch of interviews is starting. The count is the number of records or inputs in this batch. |
| `FLOW_START_INTERVIEW_BEGIN` | One interview starts, with its flow name. |
| `FLOW_ELEMENT_BEGIN` and `FLOW_ELEMENT_END` | An element started or finished, with its type and API name. |
| `FLOW_ELEMENT_DEFERRED` | The element's work was queued, as with some actions that run at the end. |
| `FLOW_ELEMENT_FAULT` | The element failed and Salesforce took the fault path, or ended the interview if none exists. |
| `FLOW_ELEMENT_ERROR` | The element failed with an error message. |
| `FLOW_ASSIGNMENT_DETAIL` | The value an Assignment element wrote to a variable. |
| `FLOW_BULK_ELEMENT_BEGIN` and `FLOW_BULK_ELEMENT_END` | A bulkified element is processing several interviews at once. |
| `FLOW_CREATE_INTERVIEW_ERROR` | The interview could not be created at all. |
| `FLOW_START_INTERVIEWS_ERROR` | The batch failed, often with the error text. |
Here is a trimmed excerpt from a record-triggered flow that failed on a Create Records element. Your exact line format and numbers will differ.
12:04:11.2 (84210000)|FLOW_START_INTERVIEWS_BEGIN|1
12:04:11.2 (84320000)|FLOW_START_INTERVIEW_BEGIN|00Dxx0000001234|Opp_Closed_Won_Task|301xx0000000AAA
12:04:11.2 (85100000)|FLOW_ELEMENT_BEGIN|00Dxx0000001234|FlowDecision|Is_Closed_Won
12:04:11.2 (85500000)|FLOW_ELEMENT_END|00Dxx0000001234|FlowDecision|Is_Closed_Won
12:04:11.2 (86000000)|FLOW_ELEMENT_BEGIN|00Dxx0000001234|FlowRecordCreate|Create_Follow_Up_Task
12:04:11.2 (91000000)|DML_BEGIN|[EXTERNAL]|Op:Insert|Type:Task|Rows:1
12:04:11.2 (95000000)|DML_END|[EXTERNAL]
12:04:11.2 (95200000)|FLOW_ELEMENT_ERROR|REQUIRED_FIELD_MISSING: Required fields are missing: [Subject]|FlowRecordCreate|Create_Follow_Up_Task
12:04:11.2 (95400000)|FLOW_ELEMENT_END|00Dxx0000001234|FlowRecordCreate|Create_Follow_Up_Task
12:04:11.2 (96000000)|FLOW_START_INTERVIEW_END|00Dxx0000001234|Opp_Closed_Won_TaskRead it from the bottom up when you hunt for a failure. The error line names the element (Create_Follow_Up_Task), its type (FlowRecordCreate), and the cause (the Subject field is empty). The lines above it show the path the interview took to get there.
Following variable values
Errors often come from a variable holding a value you did not expect. Two features help:
FLOW_ASSIGNMENT_DETAILlines record each assignment. You see the variable name, the operator, and the new value.- Flow Builder lets you add a Custom Error or Apex action to write values out. For one-off diagnosis, call a small invocable Apex method that runs
System.debug, so the value appears at theDEBUGlevel.
Here is a minimal invocable method for that purpose. Remove it before you deploy to production.
public with sharing class FlowDebugLogger {
@InvocableMethod(label='Log Value' description='Writes a value to the debug log')
public static void logValue(List<String> messages) {
for (String message : messages) {
System.debug(LoggingLevel.DEBUG, 'FLOW VALUE: ' + message);
}
}
}In the flow, add an Action element, pick Log Value, and pass a text template such as Opp {!$Record.Id} amount {!$Record.Amount}. Then filter the log for FLOW VALUE.
The method takes a List<String> because invocable methods receive one list entry per interview in a bulk run. A method that accepted a single value would not compile as an invocable method.
Seeing where the transaction spent its limits
Flow failures often come from governor limits rather than logic errors. The log can show this in two ways.
First, look at the LIMIT_USAGE_FOR_NS block, which the log writes at the end of a transaction. It lists usage per namespace:
Number of SOQL queries: 87 out of 100
Number of query rows: 4200 out of 50000
Number of DML statements: 41 out of 150
Number of DML rows: 310 out of 10000
Maximum CPU time: 8420 out of 10000Numbers close to the limit are warnings even when the transaction succeeded. Because all automation in a transaction shares these limits, a flow may be innocent. The cause may be Apex triggers, other flows, or a process on the same object.
Second, count repeated events. Filter on SOQL_EXECUTE_BEGIN and DML_BEGIN and look at how many appear between FLOW_ELEMENT_BEGIN lines for the same element. If a Get Records or Update Records element repeats once per record, it sits inside a loop. The log gives you the element name, so you can find and move it.
The pattern to look for:
FLOW_ELEMENT_BEGIN|...|FlowLoop|Loop_Contacts
FLOW_ELEMENT_BEGIN|...|FlowRecordLookup|Get_Account
SOQL_EXECUTE_BEGIN|[EXTERNAL]|SELECT Id, Name FROM Account WHERE Id = :tmpVar1
FLOW_ELEMENT_END|...|FlowRecordLookup|Get_Account
FLOW_ELEMENT_BEGIN|...|FlowLoop|Loop_Contacts
FLOW_ELEMENT_BEGIN|...|FlowRecordLookup|Get_Account
SOQL_EXECUTE_BEGIN|[EXTERNAL]|SELECT Id, Name FROM Account WHERE Id = :tmpVar1The same query runs again for each loop pass. With 200 records, this exceeds 100 SOQL queries and fails with Too many SOQL queries: 101.
Tracing the order of automation
A save can trigger several things: before-save flows, Apex before triggers, validation rules, after-save flows, Apex after triggers, and more. The log shows them in the order they ran, which helps when two automations disagree. Look for these markers:
CODE_UNIT_STARTEDandCODE_UNIT_FINISHEDmark the start and end of each unit of work, includingFlow:Opportunityfor a record-triggered flow andWorkflow:Opportunityfor the whole save.VALIDATION_RULEandVALIDATION_FAILmark validation checks.ENTERING_MANAGED_PACKAGEmarks calls into a package, which can hide logic you cannot read.
A common surprise is a flow that runs a second time because another flow or trigger updated the same record. In the log you will see two FLOW_START_INTERVIEWS_BEGIN lines for the same flow in one transaction. Add entry conditions, or use "only when a record is updated to meet the condition requirements", to stop the extra run.
Common problems when reading logs
- No log appears. The trace flag expired, you traced the wrong user, or the transaction ran as Automated Process. Check the trace flag's expiration date and the entity.
- Flow events show but no element detail. The Workflow category is below
FINER. Raise it and rerun. - The log is cut off. It hit the 20 MB cap. Lower categories you do not need, such as Visualforce and Callout, and keep the trace window short.
- A fault path hides the error. If a fault path catches the failure and routes to an email or a subflow, the transaction may succeed. Look for
FLOW_ELEMENT_FAULTlines, which appear even when no error reaches the user. - Debug logs in a scheduled or asynchronous run. Asynchronous work writes a separate log from the transaction that queued it. Trace the user the job runs as, and search the later log, not the one from the original save.
- Production tracing. You can trace in production, but logs expose record data and field values. Limit the trace window, and delete logs when you finish.
A repeatable workflow
- Reproduce the failure once, so you know the exact action and the user who performs it.
- Create a trace flag for that user with the debug level above, expiring in an hour.
- Run the action once.
- Open the log and filter on
FLOW_ELEMENT_ERRORorFLOW_ELEMENT_FAULT. Note the element name. - Filter on
FLOW_START_INTERVIEWS_BEGINto see how many times the flow ran. - Check
LIMIT_USAGE_FOR_NSfor numbers near a limit. - Fix the cause, then run the action again and confirm that the error is gone.
- Delete the trace flag and the old logs.
Exercise
A scheduled flow fails every night, but when you trace your own user and run the same logic by hand, no error appears. The log you collected shows nothing from the scheduled run. What is the most likely cause, and what do you change?
Show answer
Scheduled flows run as the Automated Process user, so a trace flag on your own user does not capture them. Create a trace flag whose traced entity is the Automated Process user, set the Workflow category to FINER, wait for the next scheduled run (or use a test schedule a few minutes ahead), then filter the new log for FLOWELEMENTERROR and FLOWELEMENTFAULT.
Exercise
A debug log for a record-triggered flow shows the same Get Records element running 200 times in one transaction, then ends with "Too many SOQL queries: 101". Which events confirm that the query sits inside a loop, and how do you fix the flow?
Show answer
The log shows FLOWELEMENTBEGIN for the Loop element followed by FLOWELEMENTBEGIN for the Get Records element and a SOQLEXECUTEBEGIN event on every pass. Move the Get Records element before the loop so it runs once and returns a collection, then use the collection inside the loop. Do the same for any Update or Create Records element: add records to a collection variable in the loop and run one DML element after the loop.