Sub topic 1
What Salesforce Does When a Deployment Fails
Prerequisites
Assume you understand Salesforce metadata, package.xml manifests, basic Git, and Salesforce CLI commands. A deployment is the process of moving metadata, such as Apex classes, fields, or flows, into an org.
What Salesforce Does When a Deployment Fails
Salesforce validates components and runs required tests during deployment. If a component has an error or a test fails, the deployment status becomes Failed.
With the usual all-or-nothing behavior, Salesforce does not commit the deployment's metadata changes. This is controlled by the rollbackOnError setting. A deployment that uses rollbackOnError=false can leave successful components in the org even when other components fail, so always check the deployment report.
Reading the Deployment Report and Test Failures
The report identifies the deployment job, component errors, and test failures. Retrieve it with the job ID:
sf project deploy report --job-id 0AfXXXXXXXXXXXXXXX --target-org prodLook for:
- The overall status, such as
Succeeded,Failed, orCanceled. - The component type, full name, and line number for metadata errors.
- Test method names, failure messages, and stack traces.
- Whether the failure happened during validation, compilation, or Apex testing.
A compilation error points to metadata that needs correction. A test failure may indicate a real regression or an incomplete test setup. Do not start rollback work until the report confirms whether Salesforce committed anything.
Failed Deployment or Bad Release?
Choose the recovery path from the final state:
| Situation | First action |
|---|---|
| Deployment failed and rolled back | Fix the reported error and deploy again |
| Deployment succeeded but causes harm | Stop further releases and restore the previous version |
| Deployment is still running | Inspect its status and cancel it if necessary |
For a successful but harmful release, identify the exact previous source version. A Git revert creates a recorded rollback change; redeploying that source restores metadata that still exists in the repository.
Exercise
A deployment reports a failed Apex test. Should you immediately redeploy the previous release?
Show answer
No. First confirm the deployment status and rollback behavior. If Salesforce rolled it back, fix the test or code and retry. Redeploy the previous release only if harmful changes were committed.