Sub topic 4
Flow Builder and the flow types
This chapter assumes you know the Salesforce data model, can navigate Setup, and have read the earlier chapters on the automation landscape and the clicks-before-code principle. Reading simple Apex helps for the last example but is not required. Later chapters cover record-triggered, screen, scheduled and Orchestrator flows in detail. Here you learn what they share: the builder, the building blocks, and how each type starts.
What Flow Builder is
Flow Builder is the visual tool in Setup where you design a flow. A flow is a saved definition of logic that Salesforce runs on demand. It has three parts you will use constantly:
- The canvas, where you connect elements into a path.
- The toolbox, where you add elements and create resources.
- The Manager tab, which lists your resources (variables, formulas and so on).
Every flow has a Start element. The Start element decides how the flow begins, and that choice fixes the flow type. You cannot change a flow's type after you create it. You would rebuild it, though a screen flow and an autolaunched flow can sometimes be converted by changing the start settings.
The flow types
| Flow type | Starts when | Typical use |
|---|---|---|
| Screen flow | A user opens it (button, action, page, utility bar) | Guided data entry, wizards |
| Record-triggered flow | A record is created, updated or deleted | Field updates, related records, notifications |
| Schedule-triggered flow | A set time, once or repeating | Nightly cleanup, reminder batches |
| Platform event-triggered flow | A platform event message is published | Reacting to external or system events |
| Autolaunched flow (no trigger) | Called by something else: Apex, another flow, REST API, a button action | Reusable logic, subflows |
| Orchestration | A record change or another flow starts it | Multi-step, multi-user processes |
Only screen flows can show screens. The other types run without a user interface, so they cannot ask anyone a question midway. Design around that. If a record-triggered flow needs a human decision, hand the work to a screen flow, an approval process or an orchestration.
Elements, resources and the flow's data
Elements do work. They fall into three groups:
- Interaction elements: Screen, Action (including invocable Apex, email alerts and Quick Actions) and Subflow.
- Logic elements: Assignment, Decision, Loop, Collection Filter, Collection Sort and Transform.
- Data elements: Get Records, Create Records, Update Records and Delete Records.
Resources hold values the elements use:
- Variables hold one value, a record, or a collection of either.
- Constants hold values that never change.
- Formulas compute a value each time they are read.
- Text templates hold formatted text.
- Choices feed screen components.
A variable has two availability settings: "Available for input" (a caller can pass a value in) and "Available for output" (a caller can read the value after the flow ends). A common error is building a subflow and forgetting to tick output, then wondering why the parent flow sees nothing.
Prefer collection variables over single record variables when you work with several records. A Get Records element that returns many records gives you one collection. Updating that collection takes one Update Records element, which means one DML operation.
Flows share the transaction's limits
A flow is not exempt from governor limits. A record-triggered flow, an Apex trigger and a validation rule that fire on the same save all spend from the same budget. For example, that includes 100 SOQL queries and 150 DML statements per synchronous transaction.
Record-triggered flows are bulkified for you, so a data load of 200 records runs the flow in batches. This does not protect you from one specific mistake: placing Get, Create, Update or Delete elements inside a Loop. Each pass of the loop spends one query or DML statement. Collect changes in a collection inside the loop, then write them once after it.
Handling errors
Elements that touch data can fail, for example on a validation rule or a required field. Without a fault path, the flow stops, rolls back the transaction, and shows an error to the user. Add a fault connector to data and action elements. Route it to an element that logs the error or sends a message to an admin, so failures are visible and not silent. The monitoring chapter returns to this.
Run context and security
How a flow runs controls what it can see and change:
- Screen flows and autolaunched flows have a "How to run the flow" setting: user context, system context with sharing, or system context without sharing.
- Record-triggered flows run in system context, so they ignore the saving user's field-level security and object permissions. A flow can therefore write to a field the user cannot edit. Check that this is intended.
Versions and activation
A flow can have many versions, but only one is active at a time. Saving after an edit to an active flow creates a new version. It does not take effect until you activate it. Older versions stay available for rollback. Use the Debug button before activation, and use the "Run flow as" and rollback options for record-triggered flows to test without committing data.
Give flows names that say object, trigger and purpose, such as Account_BeforeSave_SetRating. Names are the main way you tell flows apart later, when several act on one object.
Extending a flow with Apex
When a flow almost fits but needs one step Flow cannot do, expose that step as an invocable method. The flow calls it from an Action element. This keeps most logic visible to admins and confines code to one tested unit.
public with sharing class RecalculateRatingAction {
public class Request {
@InvocableVariable(required=true label='Account Ids')
public List<Id> accountIds;
}
@InvocableMethod(label='Recalculate Account Rating'
description='Sets Rating to Hot or Warm based on AnnualRevenue')
public static void recalculate(List<Request> requests) {
Set<Id> ids = new Set<Id>();
for (Request r : requests) {
if (r.accountIds != null) {
ids.addAll(r.accountIds);
}
}
List<Account> accounts = [
SELECT Id, AnnualRevenue FROM Account WHERE Id IN :ids
];
for (Account acc : accounts) {
acc.Rating = (acc.AnnualRevenue != null && acc.AnnualRevenue >= 1000000)
? 'Hot' : 'Warm';
}
update accounts;
}
}An invocable method receives a list because Salesforce may batch several flow interviews into one call. The method uses one query and one DML statement for the whole batch. A method that handles only requests[0] is a bug that appears only under bulk load.
Common mistakes
- Choosing the wrong type, then trying to force it. A record-triggered flow cannot show a screen.
- Putting data elements inside loops.
- Skipping fault paths on data elements.
- Forgetting "Available for output" on subflow variables.
- Assuming a record-triggered flow respects the user's permissions.
- Leaving a new version saved but not activated.
Exercise
A flow must run when an Opportunity is closed won, look up the Account's open Cases, and close each one. A developer puts Get Records for the Cases outside a Loop, then puts an Update Records element inside the Loop to close each Case. What type of flow fits, and what should change?
Show answer
A record-triggered flow on Opportunity fits, because the work starts when a record is saved. The Update Records element should not be inside the Loop. Inside the loop, use an Assignment element to set the Status on each Case and add it to a collection variable. After the loop ends, use one Update Records element on that collection, so the flow uses one DML statement however many Cases exist. Also add a fault path to the Update Records element.