When a record save fires both a Record-Triggered Flow and an Apex Trigger, debugging requires layering observability.
Diagnostic order:
- Establish the order — refer to the Order of Execution. Before-save flows fire before validation rules; after-save flows fire after
aftertriggers. - Enable debug logs for the running user. Setup -> Debug Logs -> Add User. Set Apex Code to FINE+ and Workflow to FINE.
- Reproduce the issue.
- Read the debug log. Look for
FLOW_START_INTERVIEW,FLOW_ELEMENT_BEGIN/END,EXECUTION_STARTED,CODE_UNIT_STARTED [Apex Trigger],DML_BEGIN,LIMIT_USAGE_FOR_NS. The interleaved log shows exact order. - Check for re-entry — trigger updates a field, after-save flow detects, fires another save, trigger re-runs. Use static recursion guards in trigger; use
isChangedchecks in flow. - Use Flow Builder Debug — replay flow with same input, step element by element.
- Test isolated — disable trigger temporarily; reproduce. Disable flow; reproduce. Each in isolation tells you what each contributes.
- Add explicit logging —
System.debugin trigger;Flow_Log__cinsertion in flow.
Common failure modes: field updates fight each other (both write same field); validation rule fires twice (workflow re-fires); async fires before trigger commits (events publish on commit-2).
Resolution: pick one owner per field; use before-save flow for same-record updates; use after-save trigger for cross-object writes; consolidate logic when fragile.
Tools beyond basics: Apex Replay Debugger in VS Code (replay debug log step-by-step); Event Monitoring (captures every flow run with input/output, 30-day retention).
