NexBlazers Logo
NexBlazers Learn • Build • Grow
Architecture & Apex

Salesforce Flow vs Apex: Choose by Automation Density, Not by Who Builds It

Written by NexBlazers Architecture Team November 24, 2026 10 min read

"Admins build flows, developers write triggers" was a fine rule when an object had three automations. On a Case object with forty, half in Flow and half in Apex, it's how you end up with a save that nobody can predict, debug or safely change.

Salesforce's own architects have moved on from the "who" question. The current Record-Triggered Automation Decision Guide asks how much load an object carries and picks the tool from that. In this post you'll learn to measure that load, see which pattern fits each level, and get the gotchas that decide real projects: error handling, ordering, recursion, async work and bypasses.

Low density
Record-Triggered Flow
Medium density
Flow + Invocable Apex
High density
Apex triggers + framework

1. Why "clicks vs code" stopped working

Skill-based splits fail because both tools run in the same transaction. A record-triggered flow and an Apex trigger on the same object share one set of governor limits, so a cheap flow can push an expensive trigger over the CPU or SOQL limit and the error points at the wrong place. Trailhead's Avoid Flow Limits unit says it plainly: everything other automation does counts toward the same per-transaction limits.

They also interleave. In the order of execution, before-save flows run at step 3 and before triggers at step 4; after triggers run at step 8 and after-save flows at step 14. So a Flow-plus-Apex object hands control back and forth four times on one save, and every handoff is a place where one side overwrites what the other just set.

2. Measure the object, not the team

The decision guide defines automation density with three dimensions, and you assess them together:

  • Automation quantity: how many separate automations (flows, trigger actions) run for one DML event on the object.
  • Record volume: how many records arrive per transaction, especially from API loads and batch jobs.
  • Dependency sprawl: how far one save cascades into DML on related objects, such as Case to Account to Contact to a roll-up.
DensityAutomationsVolumeDownstream DMLStandard
LowFewer than 151–200 records (UI, small API loads)0–1Record-Triggered Flow
Medium15–30Standard batch work that needs careful bulkification2–4, recursion riskFlow + Invocable Apex
HighMore than 302,000–10,000+ records (Bulk API)5+, deep object graphsApex triggers + metadata framework

Score each object by its worst dimension, and by where it's heading. An Opportunity with 12 flows today that's about to get a nightly 20,000-record ERP sync is not a low-density object. The guide also asks you to factor in total daily DML volume, because the objects that change most often punish the wrong choice the hardest.

Architecture Note: Density is per object, not per org. The same org can run Lead entirely in Flow and Case entirely in Apex. What the guide warns against is mixing independent Flow and Apex entry points on one object.

3. Low density: Record-Triggered Flow

For objects with a handful of independent automations, Flow is the default, and the biggest win is putting same-record updates in a before-save flow (Flow Builder calls it "Fast Field Updates"). A before-save change rides along with the original save, so there's no second DML statement and no extra trip through the save procedure. An after-save flow that updates its own triggering record does both, which is the single most common performance mistake in Flow-heavy orgs.

Use after-save ("Actions and Related Records") for anything that touches other records. Keep each flow small with precise entry conditions, and set the run order in Flow Trigger Explorer. The guide notes that splitting logic across several flows has little performance cost; a single mega-flow is an anti-pattern because one change forces you to retest everything.

4. Medium density: Flow orchestrates, Apex computes

Once an object has 15 to 30 automations or a few levels of cascading DML, the guide recommends a hybrid. Flow stays the entry point and owns entry criteria, routing and run order, so everything is still visible in Flow Trigger Explorer. Logic Flow handles poorly, such as business-hours SLA maths, moves into an invocable Apex action that the flow calls.

public with sharing class CalculateCaseSlaAction {
  public class Request {
    @InvocableVariable(required=true) public Datetime openedAt;
  }
  public class Result {
    @InvocableVariable public Datetime slaDueAt;
  }

  @InvocableMethod(label='Calculate SLA Due Date' category='Case')
  public static List<Result> calculate(List<Request> requests) {
    // One query for the whole batch of flow interviews
    BusinessHours bh = [SELECT Id FROM BusinessHours WHERE IsDefault = true LIMIT 1];
    Long eightHours = 8L * 60 * 60 * 1000;
    List<Result> results = new List<Result>();
    for (Request req : requests) {
      Result r = new Result();
      r.slaDueAt = BusinessHours.add(bh.Id, req.openedAt, eightHours);
      results.add(r); // same position as the matching request
    }
    return results;
  }
}

Write invocable actions for a list, never for one record. When 200 records hit a record-triggered flow, the interviews are bulked into one call, so a query inside the loop would run 200 times. Return results in the same order as the requests so each interview gets its own answer.

The hybrid has three hard limits you need to know before you commit to it:

  • No before-save. Invocable Apex can't run in a before-save flow, so it can't do cheap same-record updates.
  • No after-undelete. Record-triggered flows don't fire on undelete, so that context still needs an Apex trigger.
  • A small crossing cost. Each Flow-to-Apex call adds overhead. It's fine at medium density and starts to matter at extreme volume.

5. High density: Apex triggers with a framework

Past 30 automations, thousands of records per load or five-plus levels of downstream DML, the guide favours Apex triggers, ideally driven by a metadata framework. One trigger per object hands off to a handler, and a custom metadata type (the guide's example is TriggerAction__mdt) lists which actions run and in what order, so the sequence can change without a code deployment.

trigger CaseTrigger on Case (before insert, before update,
    after insert, after update, after undelete) {
  CaseTriggerHandler.run();
}

public with sharing class CaseTriggerHandler {
  public static void run() {
    // Bypass for data loads and integration users, via a custom permission
    if (FeatureManagement.checkPermission('Bypass_Case_Automation')) return;

    if (Trigger.isAfter && Trigger.isUpdate) {
      List<Case> escalated = new List<Case>();
      for (Case c : (List<Case>) Trigger.new) {
        Case prior = (Case) Trigger.oldMap.get(c.Id);
        // Act only when the field actually changed
        if (c.Priority == 'High' && prior.Priority != 'High') escalated.add(c);
      }
      if (!escalated.isEmpty()) CaseEscalationService.notifyAccountTeams(escalated);
    }
  }
}

Apex earns its place here because of things Flow can't do at all: transaction caching in static variables, Platform Cache for data such as business hours or role maps, savepoints and partial DML success. Apex triggers are bulk triggers by design, so the same code handles one UI save and a Bulk API load. The catch is discipline: a framework only stays clean if the team is strict about using it.

6. Flow vs Apex where it actually matters

ConcernRecord-Triggered FlowApex trigger
Same-record updatesBefore-save flow, no extra DMLBefore trigger, lowest overhead
Blocking a saveCustom Error element (not in every flow type, such as subflows)addError() on a record or field, anywhere in the handler
Transaction controlAll-or-nothingSavepoints, rollback, partial success
Run orderTrigger Order in Flow Trigger ExplorerFramework only; two triggers on one event have no set order
CachingNone across flows or interviewsStatic variables, Platform Cache
UndeleteNot supportedafter undelete
VisibilityOne view per object and eventOnly as good as your framework and docs

7. The fault-path trap

Teams moving logic into Flow often add fault paths everywhere to "handle" errors. In a record-triggered flow that can be worse than nothing. Trailhead's Roll Back Changes After an Error unit explains why: when an element fails and the flow takes a fault path, nothing is rolled back. The user's save goes through and your related record quietly doesn't exist. If the data has to be all-or-nothing, end the fault path with a Custom Error element, which shows a message and rolls back the transaction.

8. Recursion and bypasses, in both tools

The guide's recursion advice is the same for both: gate logic on whether the field you care about actually changed, comparing $Record with $Record__Prior in Flow, or Trigger.new with Trigger.oldMap in Apex. Static "already ran" flags alone skip legitimate second updates.

For bypasses, use a custom permission assigned through a permission set, never hard-coded user IDs. In Flow, add a $Permission check to the entry conditions so the flow doesn't start; in Apex, check it with FeatureManagement.checkPermission() as in the handler above. Integration users and large data loads are the usual reasons.

9. Async: where both tools get into trouble

The Run Asynchronously path in a record-triggered flow is the simplest fire-and-forget option. It runs after commit and suits notifications, tasks and simple callouts, but it shares the org's daily async limits and isn't built for very high volume.

Enqueuing a Queueable from a trigger is riskier than it looks. Triggers process records in chunks of 200, so a 20,000-record load runs the trigger about 100 times, and one enqueue per run eats into the daily async limit (the greater of 250,000 or 200 times your user licenses). A trigger fired inside Batch Apex execute can enqueue only one job. For high-volume async work, the guide prefers Change Data Capture with an Apex subscriber, or a "pending" flag picked up by a scheduled flow or scheduled Apex.

Architecture Note: CDC events don't carry prior field values, so there's no equivalent of Trigger.oldMap in the subscriber. If your logic depends on "changed from X to Y", capture that in the synchronous trigger or flow before you hand off.

10. Already mixed? Treat it as technical debt

Most mature orgs have objects with uncoordinated flows and triggers side by side. The guide calls this technical debt and says to consolidate to one entry point: move Apex triggers into flows where the object is low density, consolidate flows (with invocable Apex) where it's medium, and move to a trigger framework where it's high. A practical order of work:

  1. Inventory each object: open Flow Trigger Explorer for every event and list the triggers, handler classes and managed-package automation alongside it.
  2. Score density on all three dimensions, including the loads you know are coming.
  3. Pick the target pattern per object and write it down where the next person will find it.
  4. Move one object at a time, behind automated Apex tests that cover bulk saves of 200 records.
  5. Add Salesforce Code Analyzer to your pipeline to catch Get Records inside flow loops and SOQL inside Apex loops.

Release-specific notes worth knowing: the old 2,000-element runtime cap on flows was removed in API version 57.0, and per-interview heap is 215 MB from API version 61.0 (see Flow Limits per Org). Neither changes the per-transaction governor limits, which are what you'll actually hit.

Cheat sheet: Flow or Apex?

You need to…UseWhy
Set fields on the same recordBefore-save flow / before triggerNo extra DML or recursive save
Automate a low-density objectRecord-Triggered FlowVisible, orderable, maintainable by more people
Add complex logic to a Flow-based objectInvocable Apex (bulkified)Flow keeps the entry point and order
Run 30+ automations or Bulk API loadsApex trigger + metadata frameworkCaching, transaction control, exact order
React to undeleteApex triggerFlow has no undelete trigger
Process high-volume async workCDC subscriber or scheduled batchProtects daily async limits

Density thresholds and recommendations are from the Salesforce Architects Record-Triggered Automation Decision Guide. Treat them as guidance and plan for growth, not as hard cut-offs.

Keep learning

Official Resources

Straight from Salesforce: the docs this article is based on.

Flows and triggers fighting on the same object?

Our architects can score your objects' density and plan the consolidation with you.

Book Automation Review

All information in this article was collected from publicly available resources, including official Salesforce documentation.