Concept 4 of 7Lightning Flow

Flow or Apex? A decision framework

Choosing declarative or programmatic automation by complexity, volume, performance, error handling, testability, skills and ownership, and combining them through invocable actions.

Your confidence:Not rated

Simple explanation

FactorLean to FlowLean to Apex
LogicStraightforward rules, branching, related-record updatesComplex algorithms, recursion, heavy data transformation
VolumeModerateVery large volumes, tight CPU budgets
IntegrationSimple callouts via External Services or async pathsCallouts with retries, custom auth, complex parsing
Error handlingFault paths and loggingFine-grained exceptions, partial success, finalizers
TestingFlow tests, debugUnit tests with mocks in CI
OwnersAdmins who change rules oftenDevelopers
UIScreen flows for guided processesLWC for rich, highly interactive UIs

Combine them: Flow orchestrates and calls invocable Apex for heavy steps; Apex services are exposed as invocable actions so admins can reuse them. Agree an ownership rule per object so the same responsibility isn't split.

Real-world analogy

Flow is a well-equipped kitchen with recipe cards: most dishes can be cooked by following clear steps, and the head cook (admin) can change recipes quickly. Apex is the specialist chef you call for complicated dishes. A good restaurant uses both, with clear agreement on who cooks what.

Worked example

Quote approval:

  • Flow handles discount thresholds, routing to approvers and notifications (business rules that change often).
  • An invocable Apex action calculates margin from cost data in ERP (complex logic and a callout with retries).
  • Apex trigger framework handles a high-volume order-line rollup for performance, documented as Apex-owned for that object.

Diagram

Rendering diagram…

Key points

  • Decide by complexity, volume, integration, error handling, testing, ownership.
  • Before-save flows are the best tool for simple same-record updates.
  • Apex for complex, high-volume, integration-heavy or test-critical logic.
  • Combine with invocable Apex and subflows.
  • Agree per-object ownership to avoid split responsibility.

Limits and gotchas

  • "Clicks not code" is a guideline, not a rule; complex flows can be harder to maintain than clear Apex.
  • Flows and Apex share limits in the same transaction; performance problems often come from their combination.
  • Invocable Apex must be bulk-safe, because Flow calls it with many requests at once.

🎀 How to say this in an interview

Give a balanced framework, not a preference. Interviewers want to see you'd pick Flow for simple, changing rules and Apex for complexity and volume, and that you'd combine them.

Common follow-ups

An admin built a 150-element record-triggered flow that times out. What do you do?

Profile it with debug, remove queries and DML in loops, split it into focused flows with tight entry conditions, move heavy logic into invocable Apex, and push non-urgent work to async paths.

How do you stop Flow and Apex from fighting on the same field?

A field-ownership rule per object (which automation writes which fields), documented and enforced in reviews, or a framework that orders both.