Session 87 · Salesforce Development

Salesforce Flow vs Apex — When to Use Each

Published 2026-07-02 · 12 min read · realsyllabus.com

Every Salesforce developer hits the same decision point repeatedly: should this be a Flow or should it be Apex? There is no universal answer. But there is a consistent logic, and once you have it, the decision becomes straightforward for the majority of cases.

This session covers both tools, where each one wins, where the decision gets genuinely difficult, and the mistakes developers and admins make in both directions.

What Flow is

Flow is Salesforce's declarative automation tool. You build logic visually — elements, connectors, decisions, assignments, loops — without writing code. It runs natively on the Salesforce platform with full access to your data model.

Flow replaced Workflow Rules and Process Builder, both of which Salesforce deprecated. If you are still thinking in terms of "this should be a Process Builder," update that mental model now. Flow is the recommended default for automation in Salesforce.

Flow types you need to know

The type you'll use most is Record-Triggered. It handles the vast majority of common automation scenarios and should be your first consideration when automating record-based processes.

What Apex is

Apex is Salesforce's proprietary programming language. It's Java-like in syntax, runs natively on the platform, and gives you access to capabilities that declarative tools cannot touch: raw transaction control, complex exception handling, external HTTP callouts, and fine-grained bulk processing.

The key distinction: Flow is point-and-click logic. Apex is code you write, deploy, and maintain. Both run on the platform. Both access your data. The question is which one handles the problem correctly.

The decision framework

Apply these questions in order. The first one that gives you an answer is usually the right one:

  1. Can this be built clearly in Flow? → Build it in Flow.
  2. Does this require an external HTTP callout? → Apex (or an Invocable method called from Flow).
  3. Does this involve bulk processing at scale? → Batch Apex or Queueable Apex.
  4. Is the logic too complex for Flow to express clearly? → Apex.
  5. Does the team that will maintain this know Apex? → Factor this in before choosing Apex.
  6. Is this replacing a Workflow Rule or Process Builder? → Flow.
The practical rule: start with Flow. If the logic cannot be expressed cleanly, or if bulk performance matters, move to Apex. Never use Apex to replace what Flow handles well just because you're more comfortable with code.

When Flow wins

Flow is the right tool for most Salesforce automation. Use it when:

The maintenance advantage is significant and often underweighted. A Flow can be read and modified by someone who is not a developer. When your admin needs to update a field reference at 9pm because the business changed, a Flow they can open is recoverable. A trigger they cannot open is not.

When Apex wins

Apex is necessary when the problem genuinely requires capabilities outside Flow's scope:

Governor limits and bulk processing

Governor limits are one of the primary reasons to choose Apex in certain scenarios. Salesforce limits how many SOQL queries, DML statements, and resource-intensive operations can run per transaction. Both Flow and Apex are governed — but Apex gives you direct control.

In Apex, you can explicitly bulkify DML operations, cache SOQL results, manage transaction boundaries, and use Apex interfaces designed for high-volume operations. For processing thousands of records in a single job, Batch Apex is the right tool.

If you are writing Apex and you are not thinking about bulk behaviour, you are writing Apex that will fail at scale. Apex code needs to handle 200 records as efficiently as it handles 1. Never query or perform DML inside a loop.

The hybrid pattern: Flow + Invocable Apex

The decision is not always binary. You can write Apex decorated with @InvocableMethod and call it directly from a Flow element. This lets you build the logic structure in Flow — readable, maintainable, visual — while calling Apex only for the specific part that needs code-level control.

Example: a Screen Flow that guides a user through a multi-step account creation process, with a single Invocable method call for the external address validation API. The Flow owns the structure. Apex handles the capability gap.

The scenarios table

Scenario Recommended Tool
Lead converted → create a follow-up Task due in 3 days Record-Triggered Flow
Opportunity closes → POST data to external CRM, update records from response Apex (callout)
Process 10,000 Contact records nightly to update a score field Batch Apex
User needs guided multi-step form to create Account and related Contacts Screen Flow
Replace a Workflow Rule that updates an email field on Opportunity close Record-Triggered Flow
Commission calculation: 12 conditions, multi-object DML, rollback on failure Apex trigger
Screen Flow with guided UI + single external API callout for address validation Flow + Invocable Apex

Testing

Salesforce requires 75% test coverage before you can deploy Apex to production. This forces you to write unit tests before shipping. That requirement is a feature, not just a constraint — it catches regressions before they reach your users.

Flow testing exists but the tooling is less mature. For critical business logic, Apex's mandatory coverage requirement is a form of quality enforcement that is worth having.

The maintenance cost people underestimate

Apex must be deployed via a change set or package — it goes through a managed change process. A bug in production Apex requires a deployment cycle to fix. Flow changes can be activated directly in production (though they shouldn't be, for the same change management reasons).

Apex requires a developer to maintain. If your team doesn't have a developer, Apex becomes a liability: it sits in the org, does its job, and nobody can touch it when something goes wrong. The failure mode is common and expensive.

Common mistakes in both directions

Flow in 2026

Salesforce has invested heavily in Flow's capabilities in recent years. If you haven't looked at what Flow can do in the last 12 months, look again. The platform has added:

The practical implication: scenarios that previously required Apex may now have a clean Flow solution. Check before defaulting to code.

The rule is simple: start with Flow. Move to Apex when Flow becomes a workaround. Use Invocable methods to combine both where the problem calls for it. Don't skip tests on either.

Session 88 next — Salesforce Apex Triggers

realsyllabus.com