Automation with Flow
Flow is Salesforce's main tool for automating work without code. Learn the flow types and building blocks, then build a record-triggered flow that creates a follow-up task when a Brew & Bean order becomes Ready, and learn to test and debug it.
Flow is a visual automation builder. You drag elements onto a canvas, connect them, and Salesforce runs them when something happens: a record is saved, a user clicks a button or a schedule fires. Salesforce has ended support for the older tools, Workflow Rules and Process Builder, and tells admins to build new automation in Flow. You may still meet them in old orgs.
In this tutorial you will build a record-triggered flow on the Brew & Bean data model. Prerequisite: the objects from *Data model: objects, fields and relationships* (Coffee Order with Status, Customer and Allow Activities enabled).
Flow types
Which flow for which job
| Type | Starts when | Example |
|---|---|---|
| Record-triggered flow | A record is created, updated or deleted | When an order is Ready, create a task for the barista |
| Screen flow | A user launches it (button, page, utility bar) | A guided form to create an order step by step |
| Schedule-triggered flow | At a set time, repeating | Every night, flag orders still not picked up |
| Autolaunched flow | Called by another flow, Apex or API | A reusable piece of logic |
| Platform event-triggered flow | A platform event is published | React to a message from another system |
Record-triggered flows run before save or after save. A before-save flow changes fields on the record that started it, before it is written to the database. It is very fast, so use it to set or clean fields on the same record. An after-save flow runs once the record exists, so it can create or update other records, send emails and call actions.
The building blocks
Main elements
| Element | What it does |
|---|---|
| Get Records | Finds records (like a SOQL query) |
| Create / Update / Delete Records | Changes data |
| Decision | Branches the flow by conditions (if, else if, else) |
| Assignment | Sets or changes variable values |
| Loop | Goes through a collection of records one by one |
| Screen | Shows a page to the user (screen flows) |
| Action | Sends email, posts to Chatter, calls Apex, etc. |
| Subflow | Runs another flow |
Data lives in variables (single values or records) and collections (lists of records). The record that triggered the flow is available as $Record. For an update, $Record__Prior holds the old values.
Build: task when an order is Ready
Goal: when a Coffee Order's Status changes to Ready, create a Task reminding someone to call the customer. Tasks are Salesforce's built-in to-do records. We enabled Allow Activities on Coffee Order so a Task can point to it.
Step 1: start the flow
- 1In Setup, type
Flowsin Quick Find and open Flows. Click New Flow. - 2Choose Record-Triggered Flow and click Create.
- 3In Configure Start, set Object to
Coffee Order. - 4Set Trigger to A record is created or updated.
- 5Under Set Entry Conditions, choose All Conditions Are Met (AND). Field
Status__c, operator Equals, valueReady. - 6For When to Run the Flow for Updated Records, choose Only when a record is updated to meet the condition requirements. This stops the flow firing again on every later save while the status is still Ready.
- 7Under Optimize the Flow for, choose Actions and Related Records (this makes it an after-save flow). Click Done.
Step 2: create the task
- 1Click the + under Start and choose Create Records.
- 2Label:
Create call task. How Many Records: One. How to Set the Record Fields: Use separate resources, and literal values. Object: Task. - 3Set fields:
Subject=Call customer: order is ready,Status=Not Started,OwnerId={!$Record.OwnerId},WhatId={!$Record.Id},WhoId={!$Record.Customer__c},ActivityDatecan be left empty. - 4Click Done.
Fields marked with the curly braces, like {!$Record.Id}, are Flow merge syntax: a reference to a value in the flow. In the builder you pick them from a list rather than typing.
Step 3: save, debug and activate
- 1Click Save. Label it
Coffee Order Ready Task. The API name is filled in. - 2Click Debug. In the panel, choose a Coffee Order whose Status is already Ready as the record. Tick Run flow in rollback mode so no data is really saved. Click Run.
- 3Read the debug output. It lists each element that ran and the values used.
- 4Click Activate.
- 5Open a Coffee Order and change Status from Received to Ready. Save.
- 6Open the order's Activity panel, or the Tasks tab. A new task should be there.
The order's Activity timeline shows a new open task, Call customer: order is ready, linked to the order and the customer contact. Changing Status away from Ready and back to Ready creates a second task, because each change into Ready meets the condition.Make it safe: decisions and faults
Real flows need guards. Add a Decision when the flow should take different paths. For example, only create the task when a customer is present: a decision Has customer? with the outcome rule {!$Record.Customer__c} Is Null false.
Elements that change data can fail (a required field is missing, a validation rule blocks the save). Connect each such element's Fault path to a step that handles it, for example sending an email to the admin. Without this, users see an unhelpful error and nobody knows why.
Flow best practices
| Practice | Why |
|---|---|
| Never put Get, Create, Update or Delete inside a Loop | Each one counts against governor limits; build a collection and do one operation after the loop |
| Use before-save flows for same-record field updates | Faster, and no extra save |
| Narrow entry conditions | Fewer needless runs |
| Name every element clearly (Get_Open_Orders, not Get_Records_1) | Makes the flow readable |
| Add fault paths | Errors are handled instead of hidden |
| Test with several records, not just one | Flows must handle bulk data loads |
| Keep each flow focused; use subflows | Easier to debug |
Flows can loop and hit limits
A flow that updates a record can re-trigger itself or other automation. Use precise entry conditions (as in Step 1) and avoid updating the triggering record from an after-save flow when a before-save flow would do. Flows share governor limits with code in the same transaction.
A before-save example
To set a default on the same record, use a before-save flow. For instance: when a Coffee Order is created with no Status, set Status to Received.
1. New Record-Triggered Flow, object Coffee Order, trigger A record is created, optimise for Fast Field Updates.
2. Add an entry condition: Status__c Is Null true.
3. Add an Assignment: set {!$Record.Status__c} Equals Received. No Update Records element is needed, since the change is saved with the record.
In production you might also do this with a default value on the field, which is even simpler. Prefer the simplest option that works.
Where code is better
If your flow is a huge tangle of decisions, needs complex maths, or must process very large data volumes, move that logic to Apex. Triggers are covered in *Apex triggers and governor limits*. Many teams use a hybrid: Flow for the process, Apex for the hard part, called from a Flow action.
How this comes up in interviews. Typical questions: "Types of flows?", "Before-save versus after-save?", "What replaced Process Builder?", "How do you avoid hitting governor limits in a flow?" (no data operations in loops) and "How do you debug a flow?" (the Debug button, Run History and fault emails).
I'm an admin building a Salesforce Flow for this requirement: [describe in one or two sentences].
Objects and fields involved: [list with API names].
Give me: (1) which flow type to use and whether before-save or after-save, (2) the entry conditions, (3) the elements in order, (4) what could go wrong and where to add fault paths, (5) whether Apex would be better and why. Use plain language.What to expect: Check the plan uses precise entry conditions, does not do data operations inside loops, and mentions fault handling. Build it in a sandbox or developer org first.
Try it: Extend your flow
1. Update the flow so the task's ActivityDate is today (use the built-in $Flow.CurrentDate).
2. Add a Decision so the task is only created if the Customer is not empty.
3. Build a screen flow with a screen that collects a customer's name and phone and creates a Contact. Run it from the Flows list in Setup to test it.
4. Build a schedule-triggered flow that, once a day, finds orders still in Ready status and creates a task for each one. Make sure there is no Get or Create inside a loop.
Key takeaways
- Flow is the main no-code automation tool; Workflow Rules and Process Builder are retired, so new automation goes in Flow.
- Use record-triggered flows for data changes, screen flows for user input and schedule-triggered flows for time-based jobs.
- Before-save flows change the same record quickly; after-save flows create or update other records and call actions.
- Use precise entry conditions, fault paths and clear names; never run data operations inside a loop.
- Debug with the Debug button and activate only after testing; use Apex when logic gets too complex.
Check yourself
Finishing the quiz marks the lesson as done.
1. You want to set a field on the same record that triggered the flow, as fast as possible. What should you use?
2. Why choose 'Only when a record is updated to meet the condition requirements'?
3. Where should you put a Create Records element when handling many records from a Loop?
4. Which tool should you use for NEW automation?
5. Which flow type is best for guiding a user through a multi-step form?
Saved on this device. Create a free account to keep it on every device.
Practise this with Sam
A real mock interview, out loud, with an honest scorecard. Free to start.