Sub topic 10
Rolling Back Flows and Active Configuration
This chapter assumes you know how to retrieve and deploy metadata with the Salesforce CLI, and that you have read the chapter on redeploying the previous version. Flows and some configuration types behave differently from Apex classes when you roll back. Redeploying old source does not always restore the previous behavior.
Why flows are different
A flow is stored as a Flow metadata type. Each save creates a new flow version, and only one version is active at a time. A deployment can add a version, change which version is active, or both. Rolling back means getting the right version active again, not only restoring the file.
The org keeps old versions. This gives you a fast option that needs no deployment.
Fast path: reactivate the previous version in the org
If a new flow version is causing harm, you can deactivate it or activate an earlier version in Flow Builder, under Setup > Flows. This takes effect right away and does not need a deployment or test run.
Use it as a stopgap. Then bring the source repository back in line with the org, or the next deployment will bring the bad version back.
Redeploying a previous flow version
When you redeploy flow source, the result depends on the org and the flow's status.
- In a production org, a deployed flow version is activated only if the source file has
<status>Active</status>and the flow meets the test coverage rules for deployed flows. - If the source file has
<status>Draft</status>, the deployment creates an inactive version. The bad version stays active. - A deployed flow always creates a new version number. It does not restore an old one. The old version's content comes back, but under a new number.
<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<label>Update Order Status</label>
<processType>AutoLaunchedFlow</processType>
<status>Active</status>
</Flow>This fragment shows only the status element that decides activation. A real flow file also contains its start element, elements and variables, so deploy the full file from your last good commit.
git checkout <last-good-sha> -- force-app/main/default/flows/Update_Order_Status.flow-meta.xml
sf project deploy start --source-dir force-app/main/default/flows --target-org prod --test-level RunLocalTestsCheck the active version in Flow Builder afterward. Do not assume the deployment activated it.
Flows added by the bad release
A new flow cannot be rolled back by redeploying, because the previous state is "does not exist". You have two choices:
- Deactivate it, which is quick and reversible.
- Delete it with a destructive changes manifest. You must deactivate it first, because an active flow cannot be deleted. Each version also has to be removed, so deactivating is often the practical choice during an incident.
Active configuration
Some configuration changes the behavior of the org without changing code.
| Item | Rollback approach | Watch for |
|---|---|---|
| Validation rules | Redeploy the old file, or set `<active>false</active>` | Existing records may already have been saved or blocked under the new rule |
| Profiles and permission sets | Redeploy the old version from source | Profile deployments only touch what is in the file, so added permissions may remain |
| Page layouts and record types | Redeploy the old version | Record type assignments live in profiles |
| Custom settings and custom metadata records | Redeploy the old metadata records | Custom settings values are data, not metadata |
| Scheduled Apex and flow schedules | Abort or reschedule manually | Redeploying a class does not change existing scheduled jobs |
Profiles deserve special care. A profile file lists only the permissions it mentions. If the bad release granted access to a new field, deploying the old profile may not remove it. Retrieve the profile before the release, then compare it with the current one and remove the extra entries explicitly.
Flow side effects
Rolling back a flow does not undo what it already did. A record-triggered flow that updated 5,000 records leaves those updates in place. The same applies to emails sent and records created. Plan a data fix separately. The chapter on irreversible changes covers this in more detail.
flowchart TDExercise
A release added a new flow version that wrongly updates Opportunity records. You redeploy the previous flow file, but its status is Draft. What happens, and what should you check?
Show answer
The deployment creates a new inactive version and the bad version stays active. Change the source to <status>Active</status> before deploying, or activate the correct version in Flow Builder. Then confirm which version is active. The records already updated by the bad version still need a separate data fix.