Sub topic 10
Rolling Back Flows and Active Configuration
This chapter assumes you can read a package.xml, run sf project deploy start, and use Git to revert a commit. It also assumes you know what a flow, a validation rule, and a profile are. The earlier chapters covered redeploying the previous version and deleting added components with destructive changes. Here we look at metadata that has a runtime state: flows with versions, and configuration that is switched on or off. For these, restoring the files does not always restore the behavior.
Why flows and active configuration need separate handling
Most metadata is a definition. An Apex class is either in the org with a given body or it is not. Redeploying the old body puts the org back where it was.
Flows, validation rules, triggers, and similar components have two things that can change independently:
- The definition, meaning what the component does.
- The state, meaning whether it is active and which version is the active one.
A rollback can restore the definition and still leave the wrong state. A rollback can also fix the state without touching the definition. Knowing which of the two went wrong tells you the fastest fix.
How flow versions work
A flow in an org is a container with one or more numbered versions. At most one version is active. The others are inactive, draft, or obsolete.
- Every deployment of a changed flow creates a new version number. Version numbers are never reused, so a rollback does not take you back to "version 3". It either re-activates version 3 or creates version 6 that looks like version 3.
- Older versions stay in the org until someone deletes them. This gives you a rollback path that needs no deployment at all.
- You cannot delete the active version. To remove it, you first activate a different version or deactivate the flow.
- The org keeps a limited number of versions per flow (50 at the time of writing). A team that deploys a flow often will eventually have to delete old versions before deploying again. Check the current limit in the Salesforce documentation.
A retrieve returns one version of a flow, normally the active one. If the flow has no active version, the retrieve returns the latest version. This matters for your baseline: if a flow was inactive when you took the backup, the file you saved may not be the version that was running.
Three ways to roll back a flow
| Approach | What it does | Speed | Leaves an audit trail in Git |
|---|---|---|---|
| Activate the previous version in Setup | Makes an existing older version active | Seconds | No |
| Deploy a `FlowDefinition` with `activeVersionNumber` | Same result, as a deployment | Minutes | Yes |
| Redeploy the old flow XML from Git | Creates a new version with the old logic and activates it | Minutes, plus tests | Yes |
The first option is the right emergency move when a flow is corrupting records right now. You open Setup, open Flows, select the flow, open its version list, and activate the last good version. Then, once the incident is calm, you bring Git back in line so source control matches the org.
The second option is a small, scriptable change. Create this file:
<?xml version="1.0" encoding="UTF-8"?>
<FlowDefinition xmlns="http://soap.sforce.com/2006/04/metadata">
<activeVersionNumber>3</activeVersionNumber>
</FlowDefinition>Save it as force-app/main/default/flowDefinitions/Order_Router.flowDefinition-meta.xml, then deploy it:
sf project deploy start --metadata FlowDefinition:Order_Router --target-org prodThis only works if version 3 still exists in the org. If someone deleted it, you need the third option.
The third option uses the backup you took before the release. Restore the old flow file from Git, then deploy it:
git checkout <last-good-commit> -- force-app/main/default/flows/Order_Router.flow-meta.xml
sf project deploy start --metadata Flow:Order_Router --target-org prod --test-level RunLocalTestsThe org creates a new version from that file. Whether it becomes active depends on the status value in the file and on the org's process automation settings. Treat it as a deployment to verify, not as a guaranteed activation.
Flows that started running while broken
Rolling back the flow stops new damage. It does not repair records the bad version already changed, and it does not cancel work the flow already queued. Scheduled paths, paused interviews, and asynchronous actions created by the bad version can still fire after you roll back. Check the paused and waiting interviews for that flow and decide whether to delete them. The data repair itself is covered in the chapter on what a metadata rollback cannot restore.
Active state in other components
Several components carry an on/off setting inside the metadata file. Rolling back a release that turned something on, or off, means restoring that setting.
| Component | State field in the file | Fast mitigation |
|---|---|---|
| Validation rule | `<active>true</active>` | Deploy the rule with `active` set to `false` |
| Apex trigger | `<status>Active</status>` in the `-meta.xml` file | Deploy the trigger with `Inactive` |
| Flow | Active version number | Activate the previous version |
| Workflow rule | `<active>true</active>` | Deploy the rule with `active` set to `false` |
| Assignment and escalation rules | `<active>true</active>` on the rule entry | Redeploy the previous rule set |
A validation rule that blocks every save is a common cause of a bad release. You do not have to remove it. Deploying a copy with active set to false stops the damage and keeps the rule's definition for a later fix.
<?xml version="1.0" encoding="UTF-8"?>
<ValidationRule xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Require_Region</fullName>
<active>false</active>
<errorConditionFormula>ISBLANK(Region__c)</errorConditionFormula>
<errorMessage>Region is required.</errorMessage>
</ValidationRule>Deploy it with sf project deploy start --metadata ValidationRule:Account.Require_Region --target-org prod. The file lives in the object's validationRules folder.
Deactivating is also useful when a full revert is risky. It changes one setting and leaves the rest of the release in place. Write the deactivated file back to Git as well, or the next deployment from your main branch will turn the rule on again.
Profiles, permission sets, and layouts
Permissions and layout assignments are configuration that people are using at the moment you roll back. They have an unusual deployment behavior: a deployed profile or permission set changes only what its file mentions. It does not remove permissions that the file leaves out.
This causes a common failure. A release adds a new field and grants edit access to it in a profile. You revert the profile file in Git, which now has no mention of the field, and deploy it. The grant stays in the org because the old file never said "remove access".
You have two ways to handle this:
- Delete the new component with destructive changes. When the field is deleted, its permission entries disappear with it.
- If the component stays, write the profile or permission set with the permission explicitly set to false, for example
<editable>false</editable>and<readable>false</readable>in a field permission.
Retrieving profiles has its own trap. A profile retrieve returns only the parts for the components in your manifest. A backup taken with only Profile:Admin listed can be nearly empty. Include the objects, fields, and classes that your release touches in the backup manifest so that the profile file holds their permissions.
Custom settings, custom metadata, and data-like configuration
Custom metadata type records are metadata. You can retrieve them, store them in Git, and redeploy old values. Custom setting values are data. A metadata deployment does not carry them, so a metadata rollback cannot restore them. Export them before the release with a data tool, for example sf data query, and write them down in the runbook as a data step.
The same rule applies to anything an admin edits in the UI and that is stored as a record, such as queue membership, public group membership, and approval process users. If the release depends on these and you did not export them, you cannot get the old values back.
Choosing the rollback for a flow
Verifying the rollback
A successful rollback deployment only tells you that the metadata was accepted. Verify the behavior separately.
- Open the flow, rule, or trigger in Setup and check the state, not just the deployment status.
- Run
sf project deploy reportand confirm the deployment finished with no component failures. - Re-run the user action that failed during the incident, in a test record if possible.
- Check that Git and the org agree. If you used the Setup shortcut, commit a change that records the active version, or you will redeploy the bad version at the next release.
Edge cases to plan for
- A flow that other flows call. A subflow rollback must keep the input and output variables that the parent flow expects. If the new version changed them, the parent flow can fail even after you restore the subflow. Roll back the parent and the subflow together.
- Flow with a changed object field. If the release deleted a field the old flow version uses, activating that old version fails. Restore the field first.
- Flow tests and test coverage. Deploying an active flow to production can require flow test coverage depending on settings. Plan for a test run in the rollback deployment, or use the Setup shortcut when time is short.
- Triggers and test level. Deploying a changed trigger to production runs tests. Include time for
RunLocalTestsin your estimate. - Older version deleted. Teams that clean up versions to stay under the limit can remove their own rollback target. Keep at least the previous version until the release is confirmed healthy.
Exercise
A release deployed version 7 of the flow Order_Router. The previous good version, version 6, is still in the org. Version 7 is overwriting the Owner of new orders, and sales teams are complaining right now. A reverted Git commit exists but has not been deployed. What is the fastest safe action, and what two follow-up steps should you take afterward?
Show answer
Activate version 6 in Setup, which takes seconds and needs no deployment. Then (1) check paused, waiting, and scheduled interviews that version 7 created and decide whether to delete or repair them, and fix the records it already changed. (2) Bring Git back in line, for example by deploying the reverted commit or a FlowDefinition with activeVersionNumber set to 6, so the next release does not reactivate version 7.