Sub topic 18
Flow Metadata and Moving Flows Between Orgs
This chapter assumes you can build and activate a flow in Flow Builder and have seen a schedule-triggered flow. It covers how a flow is stored as metadata and how to move it from a sandbox to production.
How a flow is stored
Every flow is saved as a metadata file of type Flow. The file lives at force-app/main/default/flows/<ApiName>.flow-meta.xml in a Salesforce DX project. Flow Builder is a visual editor over that XML.
The <start> element describes how the flow begins. For a schedule-triggered flow, it holds the object, the record filters, and the schedule:
<start>
<filterLogic>and</filterLogic>
<filters>
<field>StageName</field>
<operator>EqualTo</operator>
<value>
<stringValue>Prospecting</stringValue>
</value>
</filters>
<object>Opportunity</object>
<schedule>
<frequency>Daily</frequency>
<startDate>2025-01-01</startDate>
<startTime>02:00:00.000Z</startTime>
</schedule>
<triggerType>Scheduled</triggerType>
</start>An autolaunched flow with no trigger has no triggerType here. Its input and output variables are declared as <variables> elements with <isInput> and <isOutput> set to true.
Versions and status in metadata
Each deployed file is one flow version. The <status> element holds Active, Draft, Obsolete, or InvalidDraft. Deploying a file with Active status creates a new version and makes it the active one. Older versions stay in the org as obsolete versions.
Moving a flow between orgs
- Retrieve the flow from the source org with the Salesforce CLI.
- Review the XML in version control.
- Deploy it to the target org.
- Confirm the version and status in Setup.
sf project retrieve start --metadata Flow:Close_Stale_Cases
sf project deploy start --metadata Flow:Close_Stale_Cases --target-org productionThe target org must contain everything the flow references. That includes custom objects and fields, Apex classes called by actions, and any subflows. A missing dependency fails the deployment.
Common problems
- Missing dependencies. Deploy referenced fields, classes, and subflows first, or in the same package.
- Schedule not running after deploy. Check that the deployed version is active. A draft version does not run.
- Test coverage. Production deployments may need Apex test coverage for any Apex the flow calls. Flows themselves can also be subject to a flow test coverage setting in your org.
- Run-as user. A scheduled flow runs as the Automated Process user or a user you configure. Confirm that user exists and has access in the target org.
- Hard-coded IDs. A record ID such as
001000000000000AAAdiffers between orgs. Pass IDs as input variables or look them up with a Get Records element.
Exercise
You deployed a schedule-triggered flow to production, but it never runs. The deployment succeeded. Name two things to check.
Show answer
Check that the deployed version has status Active, because draft versions do not run. Then check that the run-as user exists in production and can access the object and fields the flow uses. Also confirm the schedule start date is not in the past with no later recurrence.