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.
Simple explanation
| Factor | Lean to Flow | Lean to Apex |
|---|---|---|
| Logic | Straightforward rules, branching, related-record updates | Complex algorithms, recursion, heavy data transformation |
| Volume | Moderate | Very large volumes, tight CPU budgets |
| Integration | Simple callouts via External Services or async paths | Callouts with retries, custom auth, complex parsing |
| Error handling | Fault paths and logging | Fine-grained exceptions, partial success, finalizers |
| Testing | Flow tests, debug | Unit tests with mocks in CI |
| Owners | Admins who change rules often | Developers |
| UI | Screen flows for guided processes | LWC 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
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.