Skip to content
Tutorials Center
My learning

Topics

Lesson 21 of 36 ยท Automation with Flow

Screen Flows, Variables and Formulas

Build guided Salesforce screen flows: screens and components, variables and formulas, choices, Decision logic, validation, and launching a flow from a page, with JavaScript stand-ins.

A screen flow is the part of Flow that talks to people. It shows a sequence of pages with input fields, choices and text, collects answers, makes decisions, and then creates or updates records. It replaces long, error-prone instructions ("first open the account, then click New Contact, then...") with a guided path that asks for exactly what is needed and nothing more. Typical examples: log a call and schedule the follow-up in one go, qualify a lead with a questionnaire, or escalate a case with required details.

In this lesson you learn the building blocks (screens, components, variables, formulas, choices), how validation works, and where you can launch a screen flow. The code is a JavaScript stand-in, because Salesforce itself cannot run on this site.

Screens and components

Add a Screen element from the canvas. A screen holds components dragged from a palette:

  • Input: Text, Number, Currency, Date, Date/Time, Email, Phone, Long Text Area, Checkbox, Toggle, Slider, Name, Address, File Upload.
  • Choice: Radio Buttons, Dropdown, Checkbox Group, Multi-Select Picklist, Visual Picker.
  • Display: Display Text (rich text with merge fields), Display Image, Data Table (shows a collection of records), Section and Columns for layout.
  • Object fields: a component that renders a real field of a record variable, including its label, help text and picklist values, for example Account.Industry.

The Lookup component lets users pick a record. Using real object fields is better than a plain text input: the platform applies the field's picklist values, required setting and formatting automatically.

Each screen has navigation buttons (Previous, Next, Pause, Finish). Pause lets a user save progress and resume later, which needs the "Let users pause flows" setting turned on and an Apex handler or default for storing the interview.

Variables and formulas

Flows keep answers in variables. The data types are Text, Number, Currency, Boolean, Date, Date/Time, Record (one record of an object), and Picklist-style values. Each variable can also be a collection that holds many values.

Reading a screen component's value: you refer to it as {!ScreenName.ComponentName} or, more safely, store the answer in a variable (a component can write straight into a variable via Store output values in newer releases).

A formula resource gives a value computed from other resources. It uses the same function set as formula fields:

TEXT
IF({!Annual_Revenue} > 1000000, "Enterprise", "Mid-Market")
TEXT(MONTH({!Close_Date})) & "/" & TEXT(YEAR({!Close_Date}))
{!Quantity} * {!Unit_Price} * (1 - {!Discount_Pct} / 100)

Formulas recalculate automatically whenever their inputs change, so you do not need an Assignment to keep them up to date. Use them for display text, for Decision conditions and for field values.

Choices and Decisions

A Decision element sends the interview down one outcome or the default outcome. Outcomes are evaluated in order, and the first one whose conditions are met wins. Always order them from most specific to least specific, and make the default outcome meaningful (for example "Needs manual review") rather than leaving it empty.

For selection lists, a Choice resource holds one option, a Record Choice Set builds options from a query (for example open opportunities of an account), and a Picklist Choice Set reuses a picklist field's values. Dynamic choices keep the flow correct when an admin edits the picklist later.

Validation and error messages

You can validate a screen component with a formula and an error message. The formula returns true when the value is valid. Examples: {!End_Date} >= {!Start_Date} or LEN({!Phone}) >= 10. A user who enters bad data sees your message next to the field and cannot press Next. Validation at the screen level catches mistakes early, but you still need validation rules and required fields on the object, because other entry points (imports, APIs) do not run your flow.

flowchart TD
  S1["Screen 1: Customer details"] --> D{"Annual revenue over 1M?"}
  D -->|"Yes"| S2["Screen 2: Enterprise questions"]
  D -->|"No"| S3["Screen 2: Standard questions"]
  S2 --> C["Create Records: Opportunity"]
  S3 --> C
  C --> F["Screen 3: Confirmation"]

A screen flow with a branch.

Launching a screen flow

A screen flow does nothing until a user starts it. You can:

  • add the Flow component to a Lightning page (record, app or home) in Lightning App Builder, with input variables set to recordId and other merge values,
  • create a quick action of type Flow on an object and put it in the page layout's actions,
  • add it to a utility bar,
  • link from a custom button or tab, or give users a URL such as /flow/My_Flow_API_Name,
  • embed it in an Experience Cloud site.

To receive the current record, create a Text variable named recordId marked Available for input; Lightning passes the Id in automatically when the flow runs from a record page or an action.

Users need the Run Flows permission (or a profile with it) to launch flows, plus access to the flow itself through a permission set or profile setting.

Stand-in: a screen flow as data

This stand-in is not Salesforce. It models a screen flow as a list of screens with validation functions, then drives it with canned answers, so you can see how validation blocks the Next button.

JS Stand-in: screens with validation

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Stand-in: a formula and decision order

JS Stand-in: first matching outcome wins

Press Run (or Ctrl + Enter) to see the console output here.

No output.

If you reversed the order of the outcomes in the stand-in, every large customer would land in "Mid-Market". The same mistake in a real Decision element is very common.

Design tips

  • One question per concept; keep screens short. Use sections and columns to avoid long scrolling.
  • Set help text on fields and write plain labels.
  • Test the flow with a user who has the same permissions as your end users, not as an admin.
  • Add a Fault path to every data element so users never see a raw error (Flow errors, debugging and testing).
  • Keep an eye on flow interviews per page: a screen flow is stateful for one user; do not use it as an integration endpoint.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How does a screen flow receive the Id of the record page it is on?

    A text variable called recordId, marked available for input, is filled in by Lightning on record pages and actions.
  2. 2. In a Decision element, two outcomes are both true. What happens?

    Outcomes are evaluated top to bottom and the first match is taken.
  3. 3. Why keep validation rules on the object even if the screen flow validates?

    Only data entered through the flow is checked by the flow; the object must protect itself.
  4. 4. What is the benefit of an Object Field component over a plain text input?

    Object field components inherit the field's definition, so they stay correct when the field changes.

Summary

  • A screen flow collects input through screens and components, then acts on the data.
  • Variables store answers; formulas compute values; Decisions branch on the first matching outcome.
  • Validate on screens for convenience, and on the object for safety.
  • Launch from a Lightning page, quick action, utility bar, button or URL; use a recordId input variable for context.

Next: Loops, collections and limits