⚡
SF DEV TOOLKIT
Apex · SOQL · LWC · Patterns
API v62.0
Declarative Automation
Flow Debugging Tips
Flows are the #1 source of mysterious bugs in Salesforce orgs. Here's a systematic approach to finding and fixing them.
1
Use Debug Mode in Flow Builder
In Flow Builder, click the bug icon (🐛) to open Debug panel. Run the flow with specific input values and trace each element's execution path, variable values at each step, and which path was taken at Decision elements.
⚡ TIP: Debug runs as your current user — switch to another user's profile in debug to test different permission scenarios.
2
Check Flow Interview Fault Emails
When a Flow hits a fault, Salesforce emails the admin. Go to Setup → Process Automation → Paused and Failed Flow Interviews for a list of all failures. Each entry shows the fault message, the element that failed, and the flow variable state at failure time.
⚡ TIP: Add a Fault Path to every element that can fail (Get Records, DML). Route to a custom notification or platform event instead of silent failure.
3
Enable Flow Logging in Debug Logs
Setup → Debug Logs → Add trace flag for your user. Set Workflow to FINEST and Callout to INFO. Run the automation, then search the log for "FLOW_" events to trace every element execution, every variable assignment, and every loop iteration in real time.
⚡ TIP: Filter the log with "FLOW_ELEMENT_FAULT" to jump straight to the error line.
4
Order of Execution — Where Does Your Flow Run?
Record-Triggered Flows run in a specific position: Before-Save flows run after Apex before triggers but before validation rules. After-Save flows run after Apex after triggers. Understanding this prevents "record not saved yet" bugs and infinite loop issues.
⚡ TIP: Before-Save flows cannot do DML on the triggering record (it's not committed). Use After-Save for cross-object updates.
5
Prevent Infinite Loops with Entry Conditions
A Flow that updates a record can retrigger itself infinitely. Always set Run Conditions to "Only when a record is created, or when a record is edited and meets the condition requirements" — and make your condition check the field value changed from something specific, not just "is not null".
⚡ TIP: Use a formula: {!$Record.Status__c} != {!$Record__Prior.Status__c} to trigger only on actual field changes.
6
Bulkification Pitfalls in Flows
Flows are bulkified per transaction — one DML statement handles all records. But loops with Get Records inside them bypass bulkification. Use collection variables and single Get Records elements outside loops. Each DML inside a loop = one SOQL per record.
⚡ TIP: "Get Records" inside a Loop is equivalent to SOQL-in-a-loop in Apex. Move it before the loop and store results in a Collection variable.
7
Governor Limit Errors in Flows
Flows share governor limits with Apex triggers in the same transaction. If a trigger calls a flow that calls Apex, all limits are shared. Error: "SOQL 101" or "DML 150 rows" in a flow usually means combined Apex + Flow consumption crossed the limit.
⚡ TIP: Use Setup → Platform Events → Event Log Files or Event Monitoring to see governor usage across the full transaction, not just the Apex log.
8
Version Management & Rollback
Salesforce keeps all Flow versions. If a new version breaks something, go to Flow Builder → open the flow → click the version dropdown → Activate the previous version instantly. No deployment needed for rollback.
⚡ TIP: Use Flow labels that include version semantics like "Order Fulfillment v3.2 (2026-02)" so rollback history is self-documenting.
Invoke Flow From Apex (for testing) Apex
// Programmatically invoke a Flow from Apex — useful for unit testing
Map<String, Object> inputs = new Map<String, Object>{
    'inputAccountId' => accId,
    'inputStatus'    => 'Active'
};

Flow.Interview myFlow = Flow.Interview.createInterview(
    'Account_Enrichment_Flow', inputs
);
myFlow.start();

// Read output variables after flow completes
String result = (String) myFlow.getVariableValue('outputResult');
System.debug('Flow output: ' + result);

// In tests: wrap in Test.startTest/stopTest to capture async flows
@IsTest
static void testFlowExecution() {
    Account acc = new Account(Name='Test');
    insert acc;
    Test.startTest();
    // Trigger record-triggered flow by updating the record
    acc.Status__c = 'Active';
    update acc;
    Test.stopTest();
    // Assert flow side-effects here
    acc = [SELECT Rating FROM Account WHERE Id = :acc.Id];
    System.assertEquals('Hot', acc.Rating);
}