Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Salesforce Developer
hard

How do you debug a complex interaction between a Flow and an Apex Trigger?

When a record save fires both a Record-Triggered Flow and an Apex Trigger, debugging requires layering observability.

Diagnostic order:

  1. Establish the order — refer to the Order of Execution. Before-save flows fire before validation rules; after-save flows fire after after triggers.
  2. Enable debug logs for the running user. Setup -> Debug Logs -> Add User. Set Apex Code to FINE+ and Workflow to FINE.
  3. Reproduce the issue.
  4. 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.
  5. 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 isChanged checks in flow.
  6. Use Flow Builder Debug — replay flow with same input, step element by element.
  7. Test isolated — disable trigger temporarily; reproduce. Disable flow; reproduce. Each in isolation tells you what each contributes.
  8. Add explicit loggingSystem.debug in trigger; Flow_Log__c insertion 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).

Why this answer works

Senior. The diagnostic order, the debug log keyword reference, and the "consolidate logic" architectural recommendation are all strong signals.

Follow-ups to expect

Related dictionary terms