Sub topic 11
What a Metadata Rollback Cannot Restore
This chapter assumes you can redeploy a previous version from Git and write a destructive changes manifest, as covered in earlier chapters. It covers the limits of that approach. A redeploy restores metadata definitions. It does not restore everything the bad release did.
Metadata Is Not Data
A deployment moves definitions: Apex classes, flows, fields, layouts. Once the new code is live, it also runs. Whatever it does to records, queues, or outside systems is outside the deployment, so redeploying the old version does not reverse it.
| What the bad release did | Does a metadata redeploy undo it? |
|---|---|
| Replaced a class, trigger, or layout | Yes. Redeploy the previous source. |
| Added a component | Only through a destructive changes manifest. |
| A trigger or flow overwrote field values on records | No. The records keep the new values. |
| A batch job or data load ran against records | No. |
| Emails, outbound messages, or callouts were sent | No. |
| Integration systems consumed platform events | No. |
| A field was deleted | Partly. See below. |
Data Written by the Bad Release
Suppose a release adds a trigger that sets Status__c to Closed on a group of orders. Rolling back the trigger stops new damage. The orders already changed stay Closed.
To fix those records, you need a copy of their earlier values. Metadata backups do not contain record data, so take a data snapshot of the fields your release can touch, alongside the metadata retrieve.
mkdir -p backup/data
sf data query \
--query "SELECT Id, Status__c FROM Order__c WHERE Status__c != null" \
--result-format csv \
--target-org prod > backup/data/order-status-before.csvFor large volumes, use a Bulk API export instead, because a plain query is limited in size. With the snapshot, you can reload the old values after the rollback, using an upsert or update through the Bulk API.
Deleted Fields and Field Type Changes
Deleting a custom field, whether by hand or with destructive changes, does not erase it immediately. Salesforce keeps a deleted custom field and its data for up to 15 days, and you can undelete it from Setup. After that the data is gone.
This creates a trap. Redeploying a field with the same API name while the deleted one is still in the recycle bin can fail or conflict with it. Undelete the original field instead of redeploying it, so the data comes back with it.
Changing a field's type is harder to reverse. Redeploying the old type definition may be rejected when the field holds data, or the conversion may already have lost values, such as text that did not fit a number or date format. Treat a type change as a one-way step and snapshot the field first.
Other Changes That Stay Behind
- Org-wide features. Some settings cannot be turned off once enabled, such as Person Accounts. Redeploying earlier settings does not help.
- Managed package upgrades. You cannot deploy an older package version as a rollback. Installing a previous version is limited to specific cases, so check the package's documentation.
- Scheduled and queued work. Jobs already scheduled or queued may keep running the new logic until you abort them.
- Permissions already used. If a release widened access and users acted on it, tightening the profile later does not undo their actions.
Deciding What You Can Undo
Plan for Irreversibility Before the Release
Add a short check to each release plan:
- List every object and field the new code writes to.
- Snapshot those fields before the deploy.
- Mark any step you cannot reverse, such as a type change, a feature switch, or a package upgrade.
- For each marked step, decide who approves it and what the fallback is. The fallback may be a fix-forward patch instead of a rollback.
When a step cannot be undone, a rollback is the wrong plan. Fixing forward with a small corrective release is often faster and safer.
Exercise
A release added a flow that changed the Stage field on 4,000 opportunities. You redeploy the previous flow version and it succeeds. Are the opportunities fixed? What should you have done before the release?
Show answer
No. The redeploy restores the flow definition, but the 4,000 opportunities keep the changed Stage values, because a metadata rollback does not touch record data. Before the release, you should have exported the Id and Stage values of the affected opportunities, for example with a data query to CSV. After the rollback you can reload those values through the Bulk API.