Sub topic 3
Failed deployment or bad release? Choosing the recovery path
When a release goes wrong, two different situations can look the same from the outside. In one, the deployment failed and Salesforce stopped it. In the other, the deployment succeeded and the org now behaves badly. The recovery steps for the two are very different, and picking the wrong one wastes time during an incident. This chapter gives you a way to tell them apart and choose the next step.
Prerequisites
This chapter assumes you can:
- Run
sf project deploy startand read its output. - Read a
package.xmlmanifest. - Use basic Git (commit, merge, revert).
- Open the Deployment Status page in Setup.
It builds on the two previous chapters: how a failed deployment is rolled back automatically, and how to read a deployment report. The recovery procedures themselves come in later chapters. Here you only decide which one applies.
Two different problems
A failed deployment is one whose final status is Failed. Salesforce validated or ran your components, hit an error, and stopped. Because production deployments are all-or-nothing, none of your components were saved. The org is in the same state as before you started.
A successful but harmful deployment (a bad release) is one whose final status is Succeeded. Every component saved and every required test passed. The release is now live, and something it contains causes trouble. Examples:
- A validation rule blocks users from saving records they could save yesterday.
- A flow throws errors for a profile you did not test with.
- A changed Apex class passes its tests but returns wrong results for real data.
- A permission set change gives access that should not exist.
The platform sees no problem in the second case, so it will not undo anything for you. You have to do it yourself.
| Question | Failed deployment | Bad release |
|---|---|---|
| Final status | `Failed` | `Succeeded` |
| Org metadata changed? | No (production) | Yes |
| Who notices first? | The person deploying | Users, monitoring, support |
| What needs fixing? | The source or the deployment settings | The live org |
| Typical recovery | Fix and redeploy | Roll back, or fix forward |
Step 1: Establish the actual status
Do not rely on what your terminal last printed. The terminal can lose its connection while the deployment keeps running on the server. Ask Salesforce directly, using the job ID.
sf project deploy report --job-id 0AfXXXXXXXXXXXXXXX --target-org prodIf you lost the job ID, the CLI can report on the most recent deployment it started from this project:
sf project deploy report --use-most-recent --target-org prodFor scripts, ask for JSON and extract the status:
sf project deploy report --job-id 0AfXXXXXXXXXXXXXXX --target-org prod --json | jq -r '.result.status'The status values you will see are:
| Status | Meaning | Org changed? |
|---|---|---|
| `Queued` | Waiting for other deployments | No |
| `InProgress` | Components or tests are being processed | Not yet committed |
| `Canceling` | A cancel request is being processed | Not yet committed |
| `Canceled` | The deployment was stopped | No |
| `Failed` | An error stopped the deployment | No (production) |
| `Succeeded` | Everything was saved | Yes |
| `SucceededPartial` | Some components saved, some did not | Yes, partly |
SucceededPartial deserves attention. It cannot happen in production. It appears only when you deploy to a sandbox with --ignore-errors, which turns off the all-or-nothing behavior. If you see it, treat the target as having a partial release. That is a bad-release problem even though some components reported errors.
Step 2: If the status is Failed
Treat this as a development problem, not an incident. Nothing was changed in the org, so no rollback is needed. The work is:
- Open the report and find the failing components and test failures (covered in the previous chapter).
- Fix the source.
- Validate again, then deploy.
Before you move on, confirm two things. First, that the target was production or a sandbox deployed without --ignore-errors. Second, that nothing else touched the org during the window, such as a second deployer or a managed package upgrade. If both are true, the org is unchanged, and the only recovery action is to try again.
One edge case is a failure that happens after you already ran a pre-deployment script. If your pipeline loads data or runs anonymous Apex before the metadata deployment, a failed deployment does not reverse those steps. Salesforce only manages the metadata. This returns in the chapter on changes a rollback cannot restore.
Step 3: If the status is InProgress or Queued
You may still be able to stop the release before it commits. This is the cheapest recovery available, so check it first when you spot a mistake early, such as the wrong manifest or the wrong target org.
sf project deploy cancel --job-id 0AfXXXXXXXXXXXXXXX --target-org prodA cancel request is not instant. The status moves to Canceling and then to Canceled. If the deployment reaches its final save step before the request is processed, it completes as Succeeded and you are in the bad-release case. Always re-run the report after canceling and read the final status. The next chapters cover cancelation in more detail.
Step 4: If the status is Succeeded
A Succeeded status only means Salesforce accepted the metadata. It does not mean the release is good. Now you decide whether to roll back or to fix forward. There are two options.
Roll back means restoring the previous metadata versions. You redeploy the last good state from source control or from a backup, and you delete components the release added. Choose this when:
- The harm is wide, such as many users blocked or an integration failing.
- You do not know the cause yet.
- The previous state is known to be good and you have a baseline for it.
- A fix would take longer than the business can wait.
Fix forward means making a new small change and deploying it. Choose this when:
- The defect is narrow and understood, such as one wrong condition in a validation rule.
- The fix is already written and tested.
- Rolling back would itself be risky, for example because users have already created records that depend on new fields.
Rollback is not free. A rollback is a second production deployment. It runs tests, takes a deployment slot, and can fail for its own reasons. Fix forward is also a deployment, but it carries new, less-tested code. Neither is automatically safer. Compare them on blast radius, time to restore service, and how certain you are about what is in each version.
A decision flow
Step 5: Confirm what the release changed
Before you roll back, know what the release contained. A rollback that restores only part of the release can leave the org in a state nobody tested. In a Git-based process, the release is usually one merge commit:
git log --merges --oneline -5
git show --stat <merge-commit-sha>The --stat output lists every file the merge changed. Compare it against the deployed manifest. If the manifest listed fewer components than the commit changed, or more, record the difference. It tells you what a rollback needs to cover. Components added by the release will need deleting, which is the subject of the destructive changes chapter. Components modified by the release will need their old versions redeployed.
Common mistakes
- Rolling back a deployment that failed. Production is already unchanged. Redeploying "the previous version" adds a pointless deployment and a new chance to fail.
- Assuming a green test run means a safe release. Tests check what they were written to check. They do not cover every profile, every data shape, or every integration.
- Reading
Succeededas "done". It means the metadata is saved. Users may still be affected. - Deploying again while the first job is unresolved. Check the first job by ID before doing anything else.
- Treating
SucceededPartialas a failure. Some of your release is live, and that mix of old and new versions may never have been tested. - Skipping the decision. Reaching for rollback by habit can be as harmful as never rolling back. State the reason you chose it.
Putting it into practice
When an alert comes in during a release window, use this sequence:
- Get the job ID and read the status from Salesforce, not from your terminal.
- If it is still running and you are sure it is wrong, cancel and re-read the status.
- If it failed, fix the source and redeploy. No rollback is needed.
- If it succeeded and users are affected, decide between rollback and fix forward, and record why.
- Start the data impact assessment.
Exercise
A teammate runs sf project deploy start against production and the terminal shows a timeout error after 33 minutes. Support then reports that users cannot save Opportunities. What should you do first, and why?
Show answer
Check the deployment's status by job ID with sf project deploy report (or --use-most-recent). The timeout only means the CLI stopped waiting. The deployment may still be running, may have failed, or may have succeeded. The Opportunity problem means a succeeded release is plausible, but you need the real status to know whether to cancel, fix the source, or roll back. Do not start a second deployment until you know.
Exercise
A production deployment ends with status Failed because two Apex tests failed. A colleague suggests redeploying the previous version from Git to roll back. Is that needed?
Show answer
No. Production deployments are all-or-nothing, so a Failed status means none of the release's components were saved and the org is unchanged. The right action is to read the test failures, fix the code or tests, validate again, and redeploy. Rolling back would add a second production deployment with no benefit.
Exercise
A release has Succeeded. One validation rule has a wrong condition that blocks about 5% of record saves. The corrected rule is written and has been tested in a sandbox. Give one argument for fixing forward and one for rolling back.
Show answer
Fixing forward is reasonable because the defect is narrow and understood, the fix is already tested, and a rollback would be another full production deployment with its own risk. Rolling back is reasonable if the fix cannot be deployed quickly or if you are not sure the rule is the only problem, because restoring the last known good version removes all uncertainty about the release. In either case, check whether records saved incorrectly during the window need repair.