Modern Salesforce admins increasingly own decisions that used to be developer-only. The boundary between "build in Flow" and "needs Apex" has shifted significantly toward declarative; Flow now handles most patterns. But some scenarios still genuinely need code.
Stay declarative when:
- Logic fits in a single object's lifecycle and can be expressed as conditions + actions.
- Performance demands are typical (single-record save, low frequency).
- You can express the rule in a flow Decision element or a validation rule formula.
- The integration target supports HTTP callouts (Flow can do those now).
- You can update related records via Get Records + Update Records.
Reach for Apex when:
- Bulkified logic on millions of records — flows hit governor limits faster than Apex on heavy operations. A scheduled batch over 10M+ rows almost certainly needs Apex Batch.
- Recursive or self-referential logic — flows can't easily call themselves; Apex handles recursion patterns better.
- Custom sharing logic (Apex Managed Sharing) — there's no declarative way to write to
__Sharetables. - Complex error handling and transaction control —
try/catch,Database.SaveResult, partial-success patterns are easier in Apex. - Performance-critical paths — every microsecond counts (e.g., real-time pricing engines, scoring algorithms running on every save).
- Wrapping a complex external service — multiple HTTP calls with conditional branching, JSON parsing, response composition. Flow can do callouts but the orchestration gets unwieldy.
- Custom UI logic — Lightning Web Components are JavaScript + Apex; declarative tools can't build truly custom interactivity.
- Custom REST/SOAP web services — exposing Salesforce as an API endpoint requires
@RestResourceor web service Apex.
Hybrid approach (often best):
- Use Flow for orchestration (events, branches, user-facing actions).
- Call Apex Invocable Methods from Flow for heavy lifting.
- Stay declarative at the top level, drop into code only where needed.
Admin habit: keep a running list of "things I'd love to do but can't without code", revisit yearly. Each Salesforce release adds Flow capabilities; problems that needed Apex two years ago may now be declarative.
Senior admins know which patterns are truly Apex-only and don't waste cycles trying to fight Flow into doing them. They also know when to pull in a developer pair early rather than discover at week 3 that the solution doesn't scale.
