Sub topic 5
Autolaunched flows: reusable automation with no trigger
This chapter assumes you know the Salesforce data model, can navigate Setup, and have opened Flow Builder. It also assumes you know what variables and the Get, Update, and Decision elements do. Apex is optional.
What an autolaunched flow is
An autolaunched flow has no trigger of its own. It does not start when a record changes, when a user clicks a button, or on a timer. It runs only when something else calls it. That caller can be another flow (through the Subflow element), Apex, the REST API, or a process that supports invoking flows.
Because it has no screen and no start condition, it works well as a reusable unit. You write the logic once, give it a clear set of inputs and outputs, and call it from several places.
In Flow Builder you create one by choosing Autolaunched Flow (No Trigger) on the new flow screen. The canvas starts with a Start element that has no trigger settings.
How it differs from other flow types
| Flow type | What starts it | Screens |
|---|---|---|
| Autolaunched (no trigger) | A caller: flow, Apex, REST | No |
| Schedule-triggered | A set date, time, and frequency | No |
| Record-triggered | A record create, update, or delete | No |
| Screen | A user, through a button, tab, or page | Yes |
Building one
A typical autolaunched flow follows this pattern:
- Create variables for the data the caller must provide. Mark them Available for input.
- Add the logic: Get Records, Decision, Assignment, Loop, Update Records.
- Create variables for results the caller needs. Mark them Available for output.
- Save, then activate.
Take a flow named Close_Stale_Cases. It receives an accountId text variable, finds that account's open cases with no recent activity, closes them, and returns the number closed in an integer variable named closedCount.
The API name matters. Callers use it to find the flow, so changing it later breaks them.
Common errors
- Variable not available. If a variable is not marked for input or output, callers cannot set or read it. The call fails or the value comes back empty.
- Flow not active. Apex and REST call the active version. If no version is active, the call fails. Subflow calls have a related behavior, covered in the activation chapter.
- Name or type mismatch. Input names are case-sensitive in code, and the data type must match the variable.
- Hidden assumptions. The flow cannot see the caller's context. Pass in everything it needs, such as the record Id, instead of expecting it to know.
- No error handling. An unhandled failure surfaces in the caller. Add fault paths, which a later chapter covers.
Where this fits
Autolaunched flows are the building block for the next chapters. You will pass data in and out with input and output variables, reuse logic with Subflow, and start a flow from Apex and REST.
Exercise
You build an autolaunched flow that updates a case. A developer calls it from Apex, but the caseId input is never received by the flow. Name two likely causes.
Show answer
The caseId variable may not be marked Available for input, or the name or data type used in the Apex input map does not match the variable. Input names are case-sensitive, so caseid would not match caseId.