Sub topic 3
Where Flow Is the Right First Choice
This chapter explains which requirements Flow handles well and why it is usually the first tool to try. It assumes you know the Salesforce data model (objects, fields, records), can find your way around Setup, and have built or at least seen a simple flow. It also assumes you know what a variable, a loop, and a collection are. Apex and governor limits get their own chapters, so they appear here only where they affect the choice.
Why Flow comes first
Flow is Salesforce's declarative automation tool. Declarative means you configure behavior in a visual builder instead of writing code. For most business requirements, starting with Flow is the sensible default, for four reasons:
- Speed. An admin can build, debug, and activate a flow without a code review cycle or a deployment pipeline.
- Visibility. The flow canvas shows the logic as a diagram. A new team member can read it without knowing Apex.
- Lower cost to change. Changing a threshold or a recipient usually means editing one element.
- Platform support. Flow is the strategic automation tool on the platform. Workflow Rules and Process Builder have reached end of support, so new declarative automation belongs in Flow.
"First choice" does not mean "only choice". It means you try Flow first and move to code when a requirement shows a specific reason to. A later chapter gives the full decision framework. This chapter covers the Flow side of it.
Flow types and the jobs they fit
Each flow type starts in a different way. Picking the right type is half of the design.
| Flow type | What starts it | Typical job |
|---|---|---|
| Record-triggered (before save) | A record is created or updated | Set fields on the same record |
| Record-triggered (after save) | A record is created, updated, or deleted | Create or update related records, send email, call actions |
| Screen flow | A user, from a button, tab, page, or action | Guided data entry, wizards, call scripts |
| Scheduled-triggered | A schedule (once, daily, or weekly) | Batch updates to records that match a filter |
| Platform event-triggered | A platform event message | React to events from other systems or processes |
| Autolaunched (no trigger) | Another flow, Apex, or an API call | Reusable logic called from elsewhere |
Flow Orchestrator builds on these types for multi-step, multi-person processes. It is a separate topic, so this chapter does not cover it.
Requirements that fit Flow well
Field updates on the triggering record
A before-save record-triggered flow changes fields on the record that started the flow. It runs before the record is written to the database, so it needs no extra update operation. This makes it much faster than an after-save flow for the same job.
Good fits:
- Default a field based on other fields. For example, set
Priorityto High whenAmountis above a threshold. - Normalize a value, such as stamping a status date when a status changes.
- Copy a value from the record's own fields into a text or formula-like field.
A before-save flow has limits. It can't create or delete other records, and it can't send email or call most actions. When the work involves anything beyond the triggering record, use an after-save flow.
Work on related records
An after-save record-triggered flow runs after the record is saved, so the record has an Id and you can act on other data. Typical uses:
- Create a follow-up Task when an Opportunity moves to a given stage.
- Update the parent Account when a child Case is closed.
- Create child records, such as onboarding tasks, from a template you define in the flow.
- Post to Chatter or send an email alert.
Use entry conditions to keep the flow from running on every save. For example, run only when StageName changes to a specific value. Entry conditions are one of the best ways to reduce noise and avoid hitting limits. If you also set the option to run only when the record is first set to meet the conditions, the flow won't fire again for later edits.
Guided user input
Screen flows have no direct equivalent in Apex. Building screens in code means writing a Lightning Web Component and its supporting classes. In a screen flow you drag in input fields, choice sets, and file uploads, then connect them with decisions. Good fits:
- A guided case-intake form that shows different questions depending on earlier answers.
- A "Convert and schedule" wizard that creates three related records in one pass.
- A call script for service agents, embedded on a Lightning record page.
Screen flows can also validate input on the screen, show or hide components conditionally, and branch on the user's answers.
Scheduled and time-based work
A scheduled-triggered flow selects records with a filter and runs once for each matching record, on a schedule you set. Examples are flagging Opportunities with no activity for 30 days, or reminding owners about contracts that expire next month.
For per-record timing, an after-save flow can use scheduled paths. A path can run a set number of days or hours before or after a date field on the record, such as 3 days before CloseDate. If the date changes, the pending work is rescheduled.
Notifications, approvals, and hand-offs
Flow can send email alerts, post to Chatter, send custom notifications, and submit records for approval. It can also call other flows as subflows. A subflow is a flow that another flow runs, so common logic lives in one place. Put shared logic, such as "assign owner by territory", in an autolaunched flow and call it from several triggers.
What an admin team gains
Flow ownership matters as much as the feature list. Admins and business analysts often own the process rules, and they can maintain a flow without a developer. Several built-in tools support this:
- Debug in Flow Builder. You can run a flow against a real record with rollback, and step through the element-by-element path.
- Fault paths. You attach an error branch to an element, so a failed create or update can send a message or log the failure instead of surfacing a raw error.
- Versions. Each save creates a new version. Only one version of a flow is active at a time, so rolling back means activating the previous version.
- Flow Trigger Explorer. For a given object, it lists the record-triggered flows, so you can see what else runs and control the order when several flows share a trigger.
Flow also has a security side. Record-triggered flows run in system context, so they can read and write records the current user cannot. Autolaunched and screen flows let you pick the run context, so check the setting when a flow is called by users. Review it deliberately and do not leave it at the default.
Signs that a requirement is stretching Flow
Flow is not free of cost. These signals suggest that a flow design is under strain. Each one points to a topic covered in a later chapter.
- Deep nesting. You have loops inside loops, or more than a screenful of decisions on one canvas. Complex flows get hard to read, and a canvas with many criss-crossing connectors is harder to review than code.
- Heavy data shaping. You need to join, group, or sort collections in ways that need many Assignment and Loop elements. Flow has collection filter and sort elements, but complex transformations take many steps.
- Large data volumes. Many records pass through one transaction. All automation shares the same governor limits, so query and DML inside a loop can fail on a bulk load. Flow's loop elements make this easy to do by accident. Put Get Records and Create/Update elements outside loops, and collect changes in a collection first.
- Logic that needs real unit tests. Flow tests exist, but they are limited compared with Apex tests.
- Callouts and complex integrations. External callouts, custom retry logic, and parsing JSON responses are hard to do declaratively.
- Reuse across many entry points. The same logic is needed from flows, APIs, and batch jobs, and a copy per flow would drift apart.
When two or three of these apply at once, consider Apex or a hybrid design. In a hybrid design, the flow keeps the orchestration and calls an Apex action for the hard part. A later chapter shows that pattern.
Common errors when building in Flow
These mistakes appear often in record-triggered flows.
- Using after-save when before-save is enough. If you only update the triggering record, a before-save flow is faster and uses fewer resources.
- Missing entry conditions. A flow with no conditions runs on every save of the object, including saves caused by other automation.
- Query or DML inside a loop. Each iteration spends one of the limited queries or DML statements. Build a collection in the loop, then run one Update Records element after it.
- Updating the triggering record in an after-save flow. A Update Records element on
$Recordin an after-save flow causes a second save, which can retrigger the same automation. Use a before-save flow for this job. - No fault path. Without one, an error rolls back the transaction and shows the user a generic message. Add fault paths to elements that can fail.
- Several flows on the same object and event. The order between them is not guaranteed unless you set it. One flow per object and event, or explicit ordering, avoids surprises. A later chapter covers this in more depth.
Exercises
Exercise
A requirement says: "When a Case is created with Priority = High, set the Escalation Date field on that same Case to today." Which flow type should you use, and why?
Show answer
A record-triggered flow that runs before save. It only changes fields on the record that triggered it, so it needs no extra DML and is the fastest option. An after-save flow would work but costs more because it saves the record a second time.
Exercise
A requirement says: "Every night, find Opportunities that have been open for more than 60 days with no activity, and create a Task for the owner." Which flow type fits, and which design mistake should you avoid inside it?
Show answer
A scheduled-triggered flow, with a filter on the open Opportunities that match the age and activity conditions. Inside the flow, do not run a Create Records element once per loop iteration. Add each Task to a collection in the loop, then use one Create Records element on the collection after the loop.
Exercise
Name three signs that a requirement may be too complex for Flow and should be considered for Apex or a hybrid design.
Show answer
Any three of these: deeply nested loops or decisions that are hard to read on one canvas, heavy data transformation across collections, large data volumes that risk governor limits, a need for detailed unit tests, external callouts with custom error handling, or logic that must be reused from many entry points.