Sub topic 10
Troubleshooting failures and missing Quick Deploy
This chapter assumes you can run sf project deploy validate, read a job ID that starts with 0Af, and know the difference between test levels. It covers two problems: a validation that fails, and a validation that succeeds but cannot be quick deployed.
Start with the report
Every diagnosis begins with the deployment report. Run it with the job ID from your validation.
sf project deploy report --job-id 0AfXXXXXXXXXXXXXXX --target-org prodThe report lists component errors, test failures, and coverage problems in separate sections. Read them in that order, because a component error can stop the tests from running at all.
Why a validation fails
Failures fall into three groups.
| Group | Typical message | Usual cause |
|---|---|---|
| Component error | `Missing required field`, `Invalid reference` | A dependency is not in the package or not in the target org |
| Test failure | `System.AssertException`, `UNABLE_TO_LOCK_ROW` | The test depends on org data, or it conflicts with other running work |
| Coverage failure | `Average test coverage across all Apex Classes and Triggers is 74%` | Not enough covered lines in production |
Component errors
These come from the metadata itself. A field referenced by a class may exist in your sandbox but not in production, and it is not in your manifest. Add the missing component to package.xml, or deploy its dependency first. Also check that the API version in the manifest is one the target org supports.
Test failures
A test that passes in a sandbox can fail in production. Common reasons:
- The test uses
SeeAllData=trueand relies on records that exist only in the sandbox. - A validation rule, flow, or required field in production rejects test data that the sandbox allowed.
- Row locks occur because a scheduled job or another deployment is running at the same time.
Fix the test so that it creates its own data. For lock errors, rerun the validation when the org is quieter.
Coverage failures
Production requires at least 75% overall Apex coverage, and every trigger must have some coverage. With RunLocalTests, a failing test also lowers coverage because the lines it did not reach are not counted. Fix test failures first, then check coverage again.
Why Quick Deploy is unavailable
A validation can succeed and still not offer Quick Deploy. Check these conditions in order.
- The tests did not run at the right level. Quick deploy needs a validation that ran tests. A validation with
NoTestRunis not eligible. UseRunLocalTests,RunAllTestsInOrg, orRunSpecifiedTestswith enough coverage. - The validation is too old. A validation stays eligible for 10 days after it completes. After that you must validate again.
- The validation did not succeed. A partial or failed result cannot be promoted.
- The target org changed in a relevant way. If another deployment changes the same components after your validation, Salesforce may no longer accept the quick deploy.
- You used the wrong ID. The quick deploy needs the ID of the validation, not the ID of an earlier failed attempt.
sf project deploy quick \
--job-id 0AfXXXXXXXXXXXXXXX \
--target-org prodIf this command is rejected, read the error text. It usually names the reason, such as an expired validation or a missing successful test run.
Decision flow
The diagram shows the order in which to check things.
Common mistakes
- Fixing a test locally and then running quick deploy on the old job ID. A fix means new code, so you must run a new validation.
- Validating with a smaller test selection than you planned to use in the release, then expecting the result to match.
- Reading only the first error. One missing component can cause many cascading errors, so fix the earliest one and rerun.
Exercise
A validation with --test-level NoTestRun finished successfully two days ago. Quick deploy is refused. What is the likely cause, and what should you do?
Show answer
Quick deploy requires that Apex tests ran during the validation, and NoTestRun runs none. Run a new validation with RunLocalTests (or another level that runs tests and meets coverage), then quick deploy using the new job ID.
Exercise
Your validation failed with 74% overall coverage and also with two test failures. Which do you fix first, and why?
Show answer
Fix the test failures first. Failing tests do not contribute to coverage, so the 74% figure may rise once they pass. Then check coverage again and add tests only if it is still below 75%.