Sub topic 2
What Flow Is and the Flow Types
Assumed background
This chapter assumes you know the Salesforce data model (objects, fields, records) and can find your way around Setup. You should have seen a simple Flow or workflow-style automation. You should also know basic programming ideas such as variables, loops, and collections.
What Flow is
Flow is Salesforce's declarative automation tool. Declarative means you build logic by configuring elements on a canvas in Flow Builder instead of writing code. A saved, runnable definition is called a flow. Each time it runs, Salesforce creates a flow interview, which is one execution of that flow with its own variable values.
A flow is built from a few kinds of parts:
- Elements are the steps on the canvas. Examples are Get Records, Create Records, Update Records, Decision, Assignment, Loop, and Action.
- Resources are the named values the flow uses. Examples are variables, collections, formulas, and constants.
- Connectors are the arrows that set the order in which elements run.
If you know programming, the mapping is close. A variable resource is a variable. A collection variable is a list. A Loop element is a for loop. A Decision element is an if statement.
The main flow types
The flow type decides what starts the flow and whether it shows a screen to a user. Choose the type first, because it limits which elements you can use.
| Flow type | What starts it | Has screens | Typical use |
|---|---|---|---|
| Record-Triggered Flow | A record is created, updated, or deleted | No | Set fields, create related records, send notifications |
| Screen Flow | A user, from a button, a page, or a utility bar | Yes | Guided data entry, wizards, call scripts |
| Schedule-Triggered Flow | A set time, once or on a repeat | No | Nightly cleanup, reminders for a batch of records |
| Autolaunched Flow (no trigger) | Another flow, Apex, or an API call | No | Reusable logic called from elsewhere |
| Platform Event-Triggered Flow | A platform event message is published | No | Reacting to events from other systems |
Record-triggered flows have one more choice. A before-save flow runs before the record is written to the database. It can change fields on the triggering record very cheaply, because it needs no separate update. An after-save flow runs after the record is saved. Use it when you need the record Id, related records, or actions such as email and calling Apex.
How a flow runs
The diagram shows the path of a record-triggered, after-save flow.
Entry conditions are rules on the Start element. They decide whether the flow runs for a record. Setting them tightly keeps the flow from running when it is not needed. This saves resources and avoids surprising side effects.
A worked example
Suppose that when an Opportunity moves to Closed Won, you want a follow-up Task for the owner. Here is how you would build it:
- Create a Record-Triggered Flow on Opportunity, triggered when a record is created or updated.
- Set the entry condition: Stage equals Closed Won. Choose "Only when a record is updated to meet the condition requirements". This stops the flow from running again on later edits.
- Choose after-save, because the Task needs the Opportunity Id.
- Add a Create Records element for a Task. Set Subject to a text value, WhatId to the Opportunity Id, and OwnerId to the Opportunity's owner.
- Save, debug with a test record, then activate.
You wrote no code. A Salesforce admin can read, change, and own this flow.
Common errors
- Choosing the wrong flow type. A Screen Flow cannot react to a record change by itself. Use a record-triggered flow for that.
- Using after-save when before-save is enough. This adds extra writes for nothing.
- Leaving entry conditions loose. The flow then fires on every edit.
- Putting queries or updates inside a Loop element. Each pass counts against limits, so move them outside the loop and work on collections.
- Forgetting to activate. A saved flow does nothing until its version is active.
Exercise
A team wants to set a field on an Account to a calculated value whenever the Account is saved. The value depends only on other fields of the same Account. Which flow type and timing fits best, and why?
Show answer
A Record-Triggered Flow set to before-save. It can change fields on the triggering record without a separate update, so it uses fewer resources than an after-save flow.
Exercise
Why should a Create Records element sit outside a Loop element, with the loop adding records to a collection instead?
Show answer
Each Create Records call inside a loop counts as its own DML statement, and a large batch can exceed the limits. Adding records to a collection and creating them once after the loop uses a single DML statement.