SfSkills Domains Docs GitHub

Home / flow / flow-resource-patterns

flow-resource-patterns

Flow resource types and when to use each: Variables, Collection Variables, Constants, Formulas, Text Templates, Choices, Stages, Picklist Choice Sets, Record Choice Sets. Covers scope, data types, and reuse patterns. Triggers: 'which Flow resource type', 'record choice set or picklist choice set', 'choice collection from records in a Flow' (the choice-set wiring itself is flow/flow-dynamic-choices). NOT for decision elements. NOT for custom metadata (use admin/custom-metadata-types).

Open the skill folder on GitHub


Flow Resource Patterns

Activate when designing or debugging a flow's data layer — variables, formulas, constants, collections, text templates, choice sets. Picking the right resource type avoids brittle assignment chains and makes the flow debuggable.

Before Starting

Core Concepts

Variable vs Constant vs Formula

ResourceMutable?Recomputes?Use when
VariableYes (via Assignment)NoHolding mutable state across elements
ConstantNoNoHardcoded value reused multiple times (e.g. record type Id)
FormulaNo (derived)Yes, every referenceComputing a value from other resources (e.g. {!Amount} * 0.1)

Collection variables

A collection holds multiple values of the same type (primitive or SObject).

SObject variables

Hold one record's fields. Initialized to null. Getting a single record populates an SObject variable; referencing a field on a null SObject throws NullPointerException-style error.

Text templates

Rich-text or plain-text blocks with merge fields. Primary use: email body, screen display. Plain-text mode needed for Send Email action if the recipient expects non-HTML.

Choice resources

ResourceSourceUse when
ChoiceHardcoded label/valueYes/No, small static lists
Picklist Choice SetPicklist field on an objectReflects admin-maintained picklist
Record Choice SetSOQL against any objectDynamic list (e.g., active accounts)
Collection Choice SetCollection variableChoices derived from in-flow data

Common Patterns

Pattern: Derived value as Formula (not Assignment)

Formula: Discounted_Amount = {!Amount} - {!Amount} * {!Discount_Rate}

Formulas stay synced; an Assignment value goes stale when inputs change.

Pattern: Collection-of-ids for IN-filter

Assignment: Add {!$Record.Id} to collection accountIds
Get Records: Contact where AccountId IN accountIds

Pattern: Email body as Text Template

Text Template with merge fields → referenced from Send Email Action Body. Easier to test than inline string concatenation in Assignments.

Pattern: Config via Constants (not hardcoded values)

Constant: DEFAULT_REGION = "NAMER"
Used in: 4 Decision elements and 1 Create Records field map

Swapping the constant in one place updates all references.

Decision Guidance

NeedResource
Hold changing valueVariable
Reuse a literal many timesConstant
Derive value from inputsFormula
Collect records / primitivesCollection Variable
Hold one recordSObject Variable
Build a formatted string/emailText Template
Let user pick from hardcoded optionsChoice
Show picklist valuesPicklist Choice Set
Show live recordsRecord Choice Set
Show in-memory collectionCollection Choice Set

Choosing Between Choice Resources

Three Flow resources present a list of options and they are not interchangeable. A Choice is one hand-typed label and value — right for a fixed yes/no or a short constant list. A Picklist Choice Set reads a picklist field's active values at run time, so the Flow follows the field without redeploying; it cannot filter. A Record Choice Set reads records with a filter and sort, maps one field to the label and one to the stored value, and can assign the chosen record's other fields to variables; it is the resource for a dynamic choice collection driven by data. A collection variable of records is not a choice resource — to offer records as choices, bind a Record Choice Set to it. Dependent choices (one set filtered by another's selection) and the metadata shapes for all three are flow/flow-dynamic-choices; this skill decides which resource fits and how it is scoped and reused.

  1. Inventory the values the flow needs: derived, cached, shared, per-element.
  2. Choose resource type per the table above.
  3. Name with a prefix that encodes scope and type (e.g. v_ variable, c_ constant, f_ formula, col_ collection, tt_ text template).
  4. Initialize SObject variables defensively (check null before dot-access).
  5. Prefer formulas over "assignment chains" for derived values.
  6. Avoid "magic number" literals in element fields — promote to Constants.
  7. Document non-obvious formulas with a Description.

Review Checklist

Salesforce-Specific Gotchas

  1. Collection variables do not deduplicate. Adding the same record twice leaves two entries; loops see both.
  2. Formulas recompute every reference. Heavy formulas referenced inside a loop multiply cost — cache in an Assignment if recompute is expensive.
  3. Formula return types cannot be changed after saving without errors in downstream references. Plan the return type upfront.
  4. {!$Record} changes meaning in scheduled paths after a DML in the same transaction — the in-memory record does not reflect mid-transaction updates.
  5. Text Template merge fields do not HTML-escape by default in rich-text mode — user-entered text can break layout or inject markup. Use plain-text mode or strip HTML before inclusion.
  6. Choice labels and values are both strings — a numeric-looking choice value is still text and must be Converted before numeric comparison.

Output Artifacts

ArtifactDescription
Resource-type decision tableQuick-reference for which resource to use
Naming conventionPrefixes for variable, constant, formula, collection
Null-guard formulaIF(ISBLANK(sobj.Field), default, sobj.Field)

Package files