Sub topic 3
Failed deployment or bad release? Choosing the recovery path
This chapter assumes you can run sf project deploy start, read a package.xml manifest, and use basic Git. The first decision in any incident is which of two situations you are in. The recovery steps differ completely.
Two different problems
A failed deployment is one that Salesforce rejected. The deployment finished with a status of Failed, or you canceled it. Because a deployment is all-or-nothing, none of its components were saved to the org. The org is in the same state as before you started.
A successful but harmful deployment is one that finished with Succeeded. Every component was saved, and something is now wrong. Users may see errors, a trigger may corrupt records, or a validation rule may block a business process. The org has changed, so you must change it back.
The word "rollback" applies only to the second case. In the first case there is nothing to undo. You fix the cause and deploy again.
Check the status first
Do not decide from a chat message or an email. Ask the org. The deployment report shows the final status and any failures.
sf project deploy report --job-id 0AfXXXXXXXXXXXXXXX --target-org prodRead the Status line and then decide.
| Status | Meaning | Org changed? | Next step |
|---|---|---|---|
| `InProgress` or `Pending` | Still running or queued | Not yet | Decide whether to cancel it |
| `Failed` | Rejected, with component or test errors | No | Fix the errors and redeploy |
| `Canceled` | You or an admin stopped it | No | Fix the reason and redeploy |
| `Succeeded` | Saved to the org | Yes | Decide whether the release needs to be undone |
| `SucceededPartial` | Appears in some deployments that use partial-save options | Partly | Treat it as a bad release and compare the org to source |
Only Succeeded and SucceededPartial require a rollback. SucceededPartial is uncommon with the Salesforce CLI defaults, where the deployment is all-or-nothing.
The decision flow
Many teams treat rollback as the default response to a bad release. A small forward fix is often faster and safer, especially when the problem is a single line of Apex or one field-level security setting. Roll back when the fix is unclear, when the harm is growing, or when you cannot reach the fix within your recovery time target.
Worked example
You deploy a release of three Apex classes and one validation rule to production. The job ID is 0AfXXXXXXXXXXXXXXX.
- A teammate says "the deployment broke Opportunities." You run the report command above.
- The output shows
Status: Succeeded. The deployment did not fail, so this is a bad release, not a failed deployment. - You check the symptom. Reps cannot close Opportunities because the new validation rule is too strict.
- A forward fix would mean editing the rule and deploying it. You estimate that review and tests take an hour. A rollback to the previous release takes about 20 minutes because you have the backup.
- You choose to roll back, then fix the rule in a sandbox afterward.
Now suppose instead the report showed Status: Failed with a test failure in OrderHelperTest. Production is unchanged. The right action is to fix the test and deploy again. A rollback would be wrong here.
Common errors
- Rolling back a failed deployment. This redeploys old versions over a healthy org and can overwrite changes that other people made since your baseline.
- Assuming that a deployment that "went through" is safe. A
Succeededstatus only means that the code compiled and tests passed. It says nothing about whether the behavior is right. - Diagnosing from the wrong org. Pass
--target-orgexplicitly. A report from a sandbox with a matching job ID format can mislead you. - Waiting too long. Each hour after a bad release, users create data that a metadata rollback cannot repair. A later chapter covers those limits.
Exercise
A deployment report shows Status: Failed with two Apex test failures. A colleague suggests redeploying the previous versions of all components to "get back to a clean state." Is that the right recovery path, and why?
Show answer
No. A failed deployment is all-or-nothing, so no components were saved and the org is unchanged. Redeploying old versions would only risk overwriting newer changes in the org. Fix the two test failures and deploy again.
Exercise
A deployment shows Status: Succeeded, but reps report that a new Apex trigger is rejecting valid records. List the two recovery options and one factor that would make you choose the rollback.
Show answer
The options are a forward fix (deploy a corrected trigger) and a rollback (redeploy the previous versions). Choose the rollback when the fix is not clear, when the harm is growing, or when a rollback is faster than reviewing and testing a fix.