Sub topic 11
What a metadata rollback cannot restore
This chapter assumes you can read a deployment report, that you have a Git baseline or a pre-release retrieve, and that you know how to redeploy a previous version and use a destructive changes manifest. Those steps restore metadata. They do not restore everything a release can change.
Why a redeploy has limits
A deployment writes metadata definitions to the org. A redeploy of the old definitions writes the old definitions back. It does not replay history. Anything the bad release changed outside the definitions stays changed. That includes records, outbound messages, background jobs, and any definition your backup file does not state explicitly.
Before you promise stakeholders a rollback, sort each change in the release into one of three groups:
- Fully reversible. Redeploying the old file returns the org to its prior state. Examples are the body of an Apex class, a Lightning component, or a validation rule.
- Reversible with a catch. The definition returns, but something attached to it does not. Examples are a deleted custom field, a changed field type, or a profile.
- Not reversible by metadata. The effect lives in data or in an external system.
Data changes made by the release
The most common irreversible effect is data. A bad release can write records in several ways:
- A new trigger or record-triggered flow updates thousands of records as users work.
- A data migration script runs as part of the release.
- A changed validation rule or default value lets bad values in.
- A new integration pushes records in from outside.
Reverting the trigger stops new bad writes. It does not fix the records already written. You need a separate data recovery step, and it needs a data backup taken before the release. A metadata retrieve contains no records.
Capture the data your release is likely to touch, as well as the metadata. Query it to CSV before you deploy:
mkdir -p backup/data
sf data query \
--query "SELECT Id, Status__c, Discount__c FROM Order__c WHERE Status__c != 'Closed'" \
--result-format csv \
--target-org prod > backup/data/order-pre-release.csvAfter a bad release, find the records that were modified during the incident window. Then compare them with the backup:
sf data query \
--query "SELECT Id, Status__c, Discount__c, LastModifiedDate FROM Order__c WHERE LastModifiedDate >= 2026-12-01T09:00:00Z" \
--result-format csv \
--target-org prod > backup/data/order-modified-since-release.csvBuild a CSV that has an Id column and the corrected values. Then apply it with a bulk update:
sf data update bulk \
--sobject Order__c \
--file backup/data/order-fixes.csv \
--wait 10 \
--target-org prodLastModifiedDate also changes when users legitimately edit records. Treat the modified-since query as a list of candidates, not a list of damage. Compare values with the backup before you overwrite anything.
If you have no targeted backup, you have three options:
- Use the Data Export service. It is a scheduled full export, so it is only as recent as its last run.
- Use field history tracking or the record's own audit data, if they were enabled on the affected fields.
- Restore from a third-party backup tool, if your organization has one.
Plan this before the release, not during the incident.
Deleted components and their data
Deleting a component with a destructive changes manifest looks like a metadata operation, but it can remove data with it.
When you delete a custom field, Salesforce marks it as deleted. It stays recoverable in Setup for 15 days, and its data is kept during that time. After that period the field and its data are purged. Deleting a custom object works the same way, and its records go with it.
This gives you two different rollback situations:
- Within the recovery window. Undelete the field or object in Setup. The data comes back with it. This is usually safer than redeploying the definition.
- After the window. You can redeploy the field definition, but you get an empty field. The old values are gone, and your own backup is the only source.
A redeploy of a field that is still in the deleted state can run into a name conflict, because the deleted field still holds the API name. Undelete it first, or erase it from the deleted state if you are sure you do not need the data.
The same rule applies to your rollback plan itself. If your rollback uses a destructive changes manifest to remove a field that the bad release added, and users have already filled in that field, you delete their data. Check whether the field holds values you need before you run the manifest.
Changes to field definitions that existing data constrains
Some definition changes cannot be reversed because the data no longer fits the old definition.
- Field length. You can increase a text field's length. You cannot reduce it below the longest value stored in the field. If the release lengthened a field and users stored long values, the old shorter definition will fail to deploy.
- Field type changes. Changing a field's type can convert or discard stored values. Changing back does not restore what was lost. A text field converted to a number keeps only values that parse as numbers. Converting it back to text does not bring back the originals.
- Restricted changes. Some changes, such as converting between relationship types, are blocked once data exists. A rollback cannot take the path in the other direction.
- Picklist values. Records can hold values you want to remove. If the release added values and users picked them, removing them from the definition leaves records with values that are no longer in the list.
For each of these, the rollback is a data operation as well as a metadata one. Plan the data fix first. Then redeploy the definition.
Effects that already left the org
Some effects left Salesforce, so no deploy can recall them:
- Emails sent by Apex, flows, or email alerts.
- Outbound messages and callouts to other systems.
- Platform events and change events already published to subscribers.
- Records created in an integrated system through a callout.
- Files or notifications sent to customers.
Reverting the code stops further effects. For what already happened, you need to contact the owners of the downstream systems, correct their records, and sometimes communicate with customers. List the external systems your release can call, and name an owner for each one in your runbook.
Queued work behaves in a similar way. Jobs that the bad release put in the queue, such as Queueable or Batch Apex, can keep running after you redeploy the old code. Check Apex Jobs in Setup and abort what should not run. Scheduled Apex also affects deployments. Production can reject a deploy that changes a class with pending or in-progress scheduled jobs, unless the org setting that allows deployments with pending Apex jobs is turned on. A rollback during an incident can hit this error. Know the setting's state before you need it.
Definitions your backup does not state
A metadata file changes only what it lists. This causes surprises in two places:
- Profiles and permission sets. A profile file only grants or revokes the entries it contains. If the bad release added a permission and your backup file never mentioned that permission, redeploying the backup does not remove it. Retrieve profiles with the specific components in the same manifest so the file lists every relevant entry. Review the result before you rely on it.
- Manual changes. An admin who changed something in Setup during the incident changed the org, not your source. Your Git baseline does not know about it. Setup Audit Trail shows recent Setup changes (it keeps 180 days), so use it to compare the org against your baseline.
Salesforce can also reject a rollback. If the older version references a component that has since been deleted, the deployment fails on the dependency. Rollback also runs the same production test rules as any other deploy, so a rollback of Apex needs the tests to pass.
Summary of reversibility
| Change in the release | Restored by redeploying old metadata? | What else you need |
|---|---|---|
| Apex class or trigger body | Yes | Check scheduled and queued jobs |
| Validation rule, layout, Lightning page | Yes | Nothing usually |
| New field, removed by destructive changes | Field only | Undelete or backup if it held data |
| Deleted field or object | Definition only, data only inside recovery window | Undelete in Setup, or data backup |
| Field type change | Definition only | Backup of the original values |
| Records written by trigger, flow, or script | No | Data backup and a corrective update |
| Emails, callouts, platform events | No | Downstream correction and communication |
| Profile or permission set additions | Only if the backup lists them | Explicit retrieve and review |
Deciding the recovery path
The order matters. Stop the source of bad writes first, then repair data, then redeploy. If you restore the records while the faulty trigger is still active, it overwrites your fixes.
Common mistakes
- Treating a green rollback deployment as proof that the org is healthy. It only proves the metadata deployed.
- Running a destructive changes manifest against a field that already holds real data.
- Restoring a data backup over records that users edited legitimately after the release.
- Redeploying a profile backup that does not list the permissions you need to revoke.
- Forgetting that a deleted field has a 15 day recovery window, and then finding out on day 16.
Exercises
Exercise
A release added a record-triggered flow that wrongly set Status_c to "Expired" on 4,000 Order_c records over two hours. You deactivate the flow by redeploying the previous flow version. Are the orders fixed? What do you do next?
Show answer
No. The redeploy stops new wrong updates, but the 4,000 records keep the wrong value. Query the records modified since the release started, compare them with the pre-release data backup, and run a corrective bulk update for the records whose values the flow changed. Check for legitimate user edits before you overwrite any record.
Exercise
Your rollback plan removes the custom field Discount__c, added by the release, with a destructive changes manifest. Users have been entering discounts for three days. What should you check, and what are your options?
Show answer
Check whether the field holds values the business needs. If it does, export the values to CSV first. The deleted field can be undeleted from Setup for 15 days, with its data. If you only need the code to stop using the field, redeploy the old code and leave the field in place until you have decided what to do with the data.
Exercise
Why might redeploying a backed-up profile fail to remove a permission the bad release granted?
Show answer
A profile file only changes the entries it lists. If the backup was retrieved without that permission being listed, deploying it does not revoke the permission. Retrieve the profile together with the relevant components, review the file, and confirm the permission is listed as false where needed.