Sub topic 15
Activating Flows and Managing Versions
This chapter assumes you can build a basic autolaunched or schedule-triggered flow in Flow Builder, and that you know how input and output variables and Subflow work from earlier chapters. You do not need Apex to follow it.
What a version is
A flow in Salesforce is a container for one or more versions. Each version holds its own elements, resources, and settings. Callers refer to the flow by its API name, such as Close_Stale_Cases. They do not choose a version. Salesforce runs the active version for them.
A flow has at most one active version. A new flow has no active version until you activate one, and the flow does nothing until then.
A version is always in one of these states:
| Status | Meaning |
|---|---|
| Draft | Never activated. You can edit it and save over it. |
| Active | The version that runs. It is read-only. |
| Obsolete | Was active once, then replaced or deactivated. It is read-only but can be reactivated. |
| Invalid Draft | Saved with errors. It cannot be activated until you fix them. |
Saving: overwrite or new version
Flow Builder gives you two save choices. The choice you have depends on the version's status.
- Save overwrites the draft you have open. It is the normal choice while you build.
- Save as New Version copies the current state into a new version with the next version number. Use it when you edit a version that is already active or obsolete. It is the only way to change one, because those versions are read-only.
The edit loop for a live flow is:
- Open the active version.
- Make the change.
- Choose Save as New Version.
- Debug the new version.
- Activate it.
When you activate version 4, Salesforce deactivates version 3 and marks it Obsolete. Callers pick up the change immediately. You never run two versions at once, and no step in between leaves the flow with no active version.
Activating: what happens for each flow type
Activating does different things depending on how the flow starts.
Autolaunched flows. Activation makes the version available to its callers. Subflow elements, the Apex Flow.Interview class, and the REST actions/custom/flow endpoint all run the active version. If a parent flow calls a subflow that has no active version, the parent fails when it reaches that element. Activate subflows before the flows that call them.
Schedule-triggered flows. Activation is what creates the schedule. The start date, time, and frequency in the Start element take effect only for the active version. Deactivating cancels the future runs. Activating a new version replaces the schedule with the one in the new version. The consequences:
- Changing a schedule always means a new version, then activation.
- If you save a new version but never activate it, the old schedule keeps running with the old filters and logic.
- A flow that is active but has a start date in the past still runs on its frequency. It does not run once to catch up.
Flow times are interpreted in the running user's time zone setting for the Start element. Check that this matches what you want, especially around daylight saving changes.
Running versions that are not active
Sometimes you need to test a draft without activating it. Flow Builder's Debug button runs the version you have open, active or not. Debug runs on a schedule-triggered flow can run against real records, and they commit data unless you select the roll-back option. Choose roll-back for a first test.
For an autolaunched flow called through a Subflow element, a debug run in the parent uses the parent's draft but the subflow's active version. If you changed the subflow, activate it before you debug the parent, or you will test the old logic.
Managing versions in Setup
Go to Setup > Flows. Each flow has a row with its label, API name, and active status. Open the row menu and choose View Details and Versions to see every version with its number, status, and last-modified date. From there you can:
- Activate any version, including an obsolete one. This is your rollback.
- Deactivate the active version.
- Delete inactive versions.
- Open a version in Flow Builder.
Be aware of these limits:
- You cannot delete an active version. Deactivate it first.
- You cannot delete a version that has paused flow interviews waiting on it. Paused interviews resume on the version they started with, even after that version is deactivated.
- A flow has a cap on versions (50 at the time of writing). When you reach it, you must delete old versions before saving a new one. Check the current limits in the Salesforce documentation.
- To delete the whole flow, delete or remove all of its versions first.
A habit that helps: keep the active version, the previous one for rollback, and delete the rest after a release. Use the flow's Description field, and the description of each version, to record why it changed. Version numbers alone say nothing.
Checking status with SOQL
The FlowDefinitionView object shows which version of each flow is active and which is newest. This is useful for audits or for checking that a release activated.
SELECT ApiName, Label, ActiveVersionId, LatestVersionId
FROM FlowDefinitionView
WHERE ApiName = 'Close_Stale_Cases'If ActiveVersionId is null, the flow has no active version and its callers will fail or its schedule will not run. If ActiveVersionId differs from LatestVersionId, someone has saved a newer version that has not been activated. That mismatch is the most common reason for "my change did not work".
Status in metadata
In the flow's metadata file, the version's state is stored in the status element.
<status>Active</status>The values are Active, Draft, Obsolete, and InvalidDraft. When you retrieve a flow with the Metadata API, you get the active version if there is one, and otherwise the latest version. A deployment contains one version of a flow. Deploying it creates a new version in the target org. In a production org, deployed flows arrive as inactive unless the Process Automation Settings option for deploying flows as active is turned on. The deployment chapter covers this in detail.
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| Edits do not change behavior | New version saved, not activated | Compare the two IDs above and activate the latest version |
| Scheduled flow stopped running | Deactivated, or replaced by a version with a different schedule | Check the active version's Start element |
| Parent flow fails at a Subflow element | The subflow has no active version | Activate the subflow |
| Cannot delete a version | It is active, or has paused interviews | Deactivate it, and resolve or delete paused interviews |
| Cannot save a new version | Version limit reached | Delete old inactive versions |
| Cannot activate | Version is Invalid Draft | Fix the errors Flow Builder lists |
Safe release routine
- Build the change as a new version.
- Debug it with roll-back enabled.
- Activate it during a quiet period, since scheduled runs use the new schedule from that moment.
- Run the
FlowDefinitionViewquery to confirm the active version. - Watch the first run, then prune old versions.
If something goes wrong, activate the previous version from View Details and Versions. This takes effect immediately and needs no deployment.
Exercise
You edit the filter on a schedule-triggered flow and click Save as New Version, but tomorrow's run still uses the old filter. What happened, and how would you confirm it with a query?
Show answer
The new version was saved but not activated, so the old version is still active and its schedule and filters still run. Query FlowDefinitionView for the flow's ApiName and compare ActiveVersionId with LatestVersionId. If they differ, activate the latest version.
Exercise
A deployment of a new subflow version succeeded, but the parent autolaunched flow now fails at its Subflow element in production. Give one likely cause and the fix.
Show answer
The deployment created the version as inactive, because production deploys flows as inactive unless the Process Automation Settings option is enabled. If the subflow has no active version, the parent fails when it reaches that element. Activate the subflow version in production, or enable deploying flows as active.