Sub topic 6
Canceling a Deployment That Is Still Running
This chapter assumes you can run sf project deploy start, read a package.xml manifest, and find a deployment's job ID. It covers the one recovery action that is cheaper than a rollback: stopping a deployment before it finishes.
Why cancel instead of waiting
A deployment that is still running has not committed anything yet. Salesforce applies a deployment as one unit. If it fails, nothing is saved. If you cancel it in time, the result is the same as a failure: the org keeps its previous metadata.
This makes cancellation the cheapest recovery option, and it is worth knowing when to use it. Common reasons:
- You deployed to production by mistake, or with the wrong manifest.
- A required test run is taking far longer than expected and is blocking other work.
- You see a problem in the source after the deployment started, such as a missing file.
The timing window
Cancellation only helps while the deployment is in a non-final state. Once the status is Succeeded, the changes are saved and you need a rollback instead.
Use the diagram below to see the states a deployment moves through.
A deployment can pass through a short Canceling state. The org stays unchanged during this time, but the deployment is still holding its lock on the metadata, so wait for Canceled before you start another one.
Cancel from the CLI
You need the job ID. The CLI prints it when the deployment starts, and it begins with 0Af. If you have lost it, you can look it up in Setup under Deployment Status.
First, check the current state:
sf project deploy report --job-id 0AfXXXXXXXXXXXXXXX --target-org prodIf the status is Queued or In Progress, cancel it:
sf project deploy cancel --job-id 0AfXXXXXXXXXXXXXXX --target-org prodThen run the report again to confirm the final status is Canceled.
You can also press Ctrl+C during sf project deploy start. This stops the CLI from waiting, but it does not necessarily stop the deployment. The deployment keeps running on the Salesforce server. Always use deploy cancel to stop it.
Cancel from Setup
In Setup, search for Deployment Status. Under In Progress, find the deployment and click Cancel. This is useful when you are not at the terminal that started the deployment, or when a colleague started it.
What cancellation does not do
Cancellation prevents a deployment from committing. It cannot undo one that has already committed. Some points to keep in mind:
- If the report already shows
Succeeded,deploy cancelhas nothing to stop. Move to the rollback path from earlier chapters. - Cancellation requires the deployment to reach a point where Salesforce can stop it. In the final phase of a deployment, the platform may finish saving before it processes your request. Check the final status instead of assuming the cancel worked.
- A canceled deployment is not a validated one. Do not use it for a quick deploy.
- Canceling does not affect other deployments that were queued behind it. Each one has its own job ID.
Common errors
| Symptom | Likely cause | What to do |
|---|---|---|
| `deploy cancel` reports the job is already complete | The deployment finished before your request arrived | Read the report. If it succeeded, start a rollback. |
| Report still shows `In Progress` after cancel | The cancel request is processing | Wait, then run the report again. |
| Wrong org error | `--target-org` does not match where the job runs | Use the alias of the org that started the deployment. |
| Job ID not found | Copied an ID from a different org or a mistyped ID | Check Deployment Status in the target org. |
A short decision rule
- Run
deploy reporton the job ID. - If it is
QueuedorIn Progressand you do not want the result, rundeploy cancel. - Run
deploy reportagain until the status isCanceled. - If it is
Succeeded, treat it as a bad release and redeploy the previous version.
Exercise
You start a production deployment, realize you used the wrong manifest, and press Ctrl+C in the terminal. Is the production org safe? What should you do next?
Show answer
Not necessarily. Ctrl+C only stops the CLI from waiting, and the deployment can keep running on the server. Run sf project deploy report --job-id <id> --target-org prod to see the status. If it is Queued or In Progress, run sf project deploy cancel --job-id <id> --target-org prod and then check that the status becomes Canceled. If it already shows Succeeded, use the redeploy-previous-version rollback.