Beginner 20 min read

Declarative vs Programmatic: When to Use Flow Instead of Apex

By the end of this lesson, you'll be able to:

  • Define "declarative" and "programmatic" in the Salesforce context
  • Name at least three factors that favor Flow over Apex for a given requirement
  • Apply a simple decision framework to a real business scenario

Prerequisites: "The Salesforce Security Model: Profiles, Permission Sets, Roles"

Two ways to tell Salesforce what to do

Declarative means configuring behavior through clicks, menus, and visual builders — no code. Programmatic means writing code — Apex. Flow is Salesforce's primary declarative automation tool: you drag elements onto a canvas ("when a Case is created, check its Priority, then send an email if it's High") and Salesforce runs that logic without a single line of Apex.

The decision framework

Favor Flow when:

  • The logic is simple "if this, then that" branching
  • An admin (not just a developer) should be able to maintain it going forward
  • It's a one-off business process specific to how your company works

Favor Apex when:

  • The logic needs loops, complex math, or intricate branching Flow struggles to express cleanly
  • You're processing large numbers of records and need fine control over bulk-safety (Module "Governor Limits and Bulk-Safe Code")
  • You need to call an external system (Module "Integrating Apex with the Outside World")
  • The same logic needs to be reused across many different contexts (a method other code can call, not just one automation)

A real business example: Sales Automation

"When an Opportunity's Stage changes to Closed Won, send a congratulations email to the Account owner" — that's a perfect Flow. It's simple, one clear trigger condition, one clear action, and any admin should be able to read and adjust it without a developer.

"When an Opportunity's Stage changes to Closed Won, recalculate a rolling 12-month revenue total across every Opportunity for that Account's entire corporate hierarchy, respecting currency conversion, and log the result to an external finance system" — that's Apex. Too much logic, too much data processing, and an external system is involved.

Trade-offs and when NOT to use this framework rigidly

This framework is a strong starting heuristic, not a hard law. Real teams sometimes choose Apex for a simple requirement because it's already part of a larger Apex-based system, or choose Flow for something moderately complex because keeping it maintainable by admins matters more than elegance. Use the framework to inform the decision, not replace judgment.

Exercise

A Loan Processing company needs: 'When a loan application's status changes to Approved, notify the applicant by email.' Using this lesson's framework, would you build this in Flow or Apex? Justify your answer.

Show hint

Is there complex math, bulk data processing, or an external system call involved? If not, lean toward the simpler tool.

Declarative vs Programmatic: When to Use Flow Instead of Apex Quiz

1. What does "declarative" mean in the Salesforce context?

2. Salesforce always recommends trying a declarative solution before reaching for Apex.

Log in to submit the quiz and save your score.

My Notes

Log in to keep private notes on this lesson.

Questions about this lesson

No questions yet — be the first to ask.

Log in to ask a question about this lesson.

Summary

Flow is Salesforce's point-and-click automation tool — declarative, meaning you configure behavior visually instead of writing code. This lesson gives you a concrete decision framework for choosing Flow vs. Apex, a decision every module from here forward will keep coming back to.