
Serpent Team

Andrew Hanna

Short answer: Salesforce has no undo button. A production deployment
that fails rolls itself back, because rollbackOnError must be true when
you deploy to production, but a deployment that succeeds and turns out to be wrong is
yours to reverse by hand. Your realistic options are a reverse deployment from a
pre-release snapshot, a targeted destructive change, or a forward fix, and which of
them is available to you is decided before you deploy, not after.
Salesforce commits metadata straight into the org. There is no transaction log to
unwind and no previous version of the org to switch back to. The Metadata API gives
you exactly one safety net, and it only covers outright failure: for a production
deployment, rollbackOnError must be set to true, so if any component in
the package fails, the whole deployment is discarded and the org is left as it was (Salesforce Metadata API developer guide).
That net does nothing for the case teams actually fear. A release that deploys cleanly, passes every test, and then breaks a business process at nine in the morning is not a failed deployment in Salesforce terms. Reversing it means building and shipping a new deployment, and you can only build that one from something you captured earlier.
This is the question every rollback plan should start with, and it is where most plans are silent. Sort your release into three buckets before you write a single step.
The third bucket is where rollback plans quietly fail. Metadata rollback restores configuration, never data. If your release ran an automation across 400,000 records, redeploying yesterday's Apex changes nothing about those records.
The most reliable option. If the branch that produced the release is in Git, the previous commit is your rollback artifact. You build a package from the last known-good commit and deploy it over the top. This only covers components the release changed or added, so it needs to be paired with strategy three.
Capture the state of the target org immediately before the deployment, then use that snapshot to generate the reverse package if you need it. This covers the case where the org has drifted from Git, which in most Salesforce teams it has. Tools in this category automate the capture and the diff: Gearset, AutoRABIT and Blue Canvas all document snapshot or restore based rollback, and Serpent ships one-click rollback on every plan, including the free one.
A reverse deployment updates components that existed before. It does not remove the
ones your release created, so a new object or field stays behind unless you delete it
explicitly. That means a destructiveChanges.xml manifest, a separate
artifact you have to write. Use destructiveChangesPre.xml to delete
before the additions land and destructiveChangesPost.xml to delete after,
which is how you unwind dependencies such as an Apex class that still references the
object you want gone.
Often the right call. If the fault is a single validation rule or one line of Apex, a hotfix through the normal pipeline is faster and safer than reversing a package of 200 components. Roll back when the blast radius is unknown. Roll forward when it is small and understood.
A rollback is a design decision made at build time. Answer these five before the release goes out.
Validating before you deploy is the cheapest prevention available. A validation with tests stays usable for 10 days and lets you quick deploy the same package without rerunning Apex tests, so there is little excuse for finding compile errors in production. More release playbooks are in our SF Guides library.
Does Salesforce roll back a failed deployment automatically?
Yes, but only for deployments that fail. Production deployments require
rollbackOnError to be true, so a failing component discards the whole
package. A successful deployment is never reversed for you.
Can change sets be rolled back?
Not natively. There is no reverse button, so teams build a second change set that redeploys the previous version, which only works if someone captured that version first.
Does a metadata rollback restore my data?
No. Metadata and data are separate problems. Reversing configuration does not undo records that an automation created, updated or deleted, so you need a backup and a restore plan for that.
How long do I have to recover a deleted custom field?
15 days. The field sits in Deleted Fields in Object Manager and can be undeleted with its data inside that window, though you may have to re-add it to page layouts manually.
Commitment free!