Sub topic 2
Reading the Deployment Report and Test Failures
This chapter assumes you can run sf project deploy start, you know what a package.xml manifest is, and you have seen an Apex test run. You will learn to find the failing components and failing tests in a deployment report, so you can choose the right recovery step.
Where the report comes from
Every deployment gets a job ID that starts with 0Af. The CLI prints it when the deployment starts. You can also find it in Setup under Deployment Status. The report for that job tells you the overall status, the counts of components and tests, and the details of each failure.
Use the job ID to ask for the report at any time:
sf project deploy report --job-id 0AfXXXXXXXXXXXXXXX --target-org prodThe command works while the deployment is running and after it ends. Keep the job ID in your release notes, because you will need it again during an incident.
The status values
The top of the report shows one status. Each value points to a different next step.
| Status | Meaning | Typical next step |
|---|---|---|
| Queued or InProgress | Salesforce has not finished | Wait, or cancel if it is harmful |
| Succeeded | All components saved and the test requirements were met | Verify behavior in the org |
| SucceededPartial | Only seen with partial deployments of some tools | Check which components were saved |
| Failed | At least one component or test failed | Read the failures and fix them |
| Canceling or Canceled | A cancel request was made or completed | Confirm the org state |
A Failed deployment normally leaves the org unchanged, because Salesforce saves nothing when any part fails. The next chapters explain what to do when the status is Succeeded but the release is still wrong.
Component failures
The report lists component failures in a table. Each row has these fields:
- Component type and name, such as
ApexClassandOrderHelper. - Problem type, usually
Error. - Problem, the message from the compiler or the metadata validator.
- Line and column, for Apex and other code.
Read the problem text before you change anything. Common causes include:
- A missing dependency, for example a field referenced in a class that is not in the manifest and not in the target org.
- A compile error caused by a different API version or a different org configuration.
- A required field or permission that does not exist in production.
Fix the first error first. One missing component often causes many later errors, and those disappear once the root cause is fixed.
Test failures
If the deployment ran tests, the report has a separate section for test failures. Each entry shows the class, the method, the error message, and a stack trace. It also shows code coverage warnings for classes below the required level.
sf project deploy validate --manifest manifest/package.xml --target-org prod --test-level RunLocalTestsThis command runs the tests without saving anything. The report it produces has the same sections as a real deployment, so you can read failures safely.
Read a test failure in this order:
- Look at the message.
System.AssertExceptionmeans the code ran and returned an unexpected result.System.NullPointerExceptionorSystem.QueryExceptionmeans the test data or the code is wrong. - Look at the stack trace. The first line that names your class is the best place to start.
- Ask whether the test depends on data that exists only in production, or only in the sandbox.
- Check coverage separately. A deployment can fail on coverage even when every test passes.
Reading the whole picture
The diagram shows how to move from the report to a decision.
Common mistakes
- Reading only the summary line. The count of failures does not tell you the cause.
- Fixing the last error in the list instead of the first.
- Treating a coverage failure as a test failure and rewriting working tests.
- Losing the job ID and having to search Deployment Status during an incident.
Exercise
A deployment to production shows status Failed with 14 component errors. Most mention "Variable does not exist: Region__c". What do you check first, and what is the state of the org?
Show answer
Check whether the custom field Region__c is in your manifest or already exists in production, because one missing field is likely the root cause of the other errors. The org is unchanged, because a failed deployment saves nothing, so no rollback is needed. Add the field to the deployment and run a validation again.