Sub topic 10
Troubleshooting failures and missing Quick Deploy
This chapter assumes you can run sf project deploy validate and sf project deploy quick. It also assumes you know the test levels and the 75% coverage rule from earlier chapters. It covers two problems: a validation that fails, and a validation that passes but offers no quick deploy.
Treat these as separate problems. A failed validation never produces a deployable result. A passed validation can still be ineligible for quick deploy. Check which one you have before you change anything.
Start with the report
Every diagnosis starts from the job ID, which begins with 0Af. Pull the full result before you guess at a cause:
sf project deploy report --job-id 0AfXXXXXXXXXXXXXXX --target-org prodIf you lost the ID, use the most recent deployment instead:
sf project deploy report --use-most-recent --target-org prodThe report has three parts, and each part points to a different class of failure:
- Component failures list metadata that could not be saved. Each row has a file, a line, and an error message.
- Test failures list Apex tests that threw an exception or failed an assertion.
- Coverage warnings list classes and triggers below the required percentage, or an org-wide average below 75%.
For machine-readable output in scripts, add --json to the validate or report command. The CLI also accepts --verbose on validate to print the test results table during the run.
Failure class 1: component errors
Component errors appear before any test runs. The server checks that the metadata is internally consistent and consistent with the target org.
Typical messages and causes:
| Message pattern | Usual cause | Fix |
|---|---|---|
| `Variable does not exist: Field__c` | An Apex class references a field the target org does not have, and the field is not in the package. | Add the field to the manifest, or deploy it first. |
| `no CustomObject named X found` | A layout, flow, or permission set references an object that is not in the deployment or the target org. | Include the object, or remove the reference. |
| `Cannot find Apex class` | A trigger or other component depends on a class missing from the manifest. | Add the class to `package.xml`. |
| `INVALID_CROSS_REFERENCE_KEY` | A reference points to an ID or API name that does not exist in the target org. | Check the API name and record type names. Check that dependent metadata exists. |
| `This component has been modified in the org` or similar conflict | Source tracking is not involved in production, but a feature or edition limit can block the component. | Read the full message. It usually names the limit. |
The common root cause is a dependency that exists in your sandbox but not in production. A validation exposes this because it compiles against the target org, not against your local project.
Check the manifest against the dependencies. Compare what the failing component references with what package.xml lists. Then confirm that those items exist in the target org.
Failure class 2: test failures
Test failures are harder to diagnose, because a test that passes in a sandbox can fail in production. Common reasons:
- Data differences. Production has real records, validation rules, duplicate rules, and required fields that a sandbox might not have. A test that inserts an
Accountcan fail on a validation rule that exists only in production. SeeAllData=true. Tests that read org data depend on what is in the org. Different data gives a different result.- Hardcoded IDs. Record type IDs and profile IDs differ between orgs. Query by name instead.
- Mixed DML or governor limits. A test that nearly hits a limit with sandbox automation can exceed it with production automation.
- Order and parallelism. Tests that lock the same records can fail with
UNABLE_TO_LOCK_ROWwhen run in parallel. Fix the test data. Disabling parallel testing in Setup is a workaround, not a fix. - Time-dependent code. Tests that depend on
Date.today()or business hours may fail on certain days.
To reproduce a test failure quickly, run the same tests in a sandbox that mirrors production. A partial-copy or full sandbox refreshed recently is closest. Use the failing class names from the report:
sf apex run test \
--tests AccountServiceTest \
--result-format human \
--code-coverage \
--wait 10 \
--target-org uatThen read the stack trace line by line. Fix the test or the code. Run the validation again, which creates a new job ID. The old failed ID is of no further use.
Failure class 3: coverage failures
Coverage failures come in two forms, and the fix differs.
- Org-wide average below 75%. This applies with
RunLocalTestsandRunAllTestsInOrg. The average covers all Apex in the target org, not just your changes. If a previous deployment lowered it, your small change can tip it under. - Per-class coverage too low. With
RunSpecifiedTests, each class and trigger in the deployment must have at least 75% coverage from the tests you named. A class covered by a test you did not list counts as uncovered.
A third case surprises people. A trigger needs some coverage. A trigger with 0% coverage fails the deployment even if the org average is high.
Read the coverage warning text carefully. It names the class and the percentage. Then decide whether to add test methods or to name more test classes with --tests.
sf project deploy validate \
--manifest manifest/package.xml \
--test-level RunSpecifiedTests \
--tests AccountServiceTest \
--tests AccountTriggerTest \
--target-org prodSpecified tests are quicker to run, but they make coverage your responsibility class by class.
Failure class 4: validation never completes
Sometimes there is no failure and no success. The CLI times out waiting, or the deployment sits in a pending state.
- The CLI wait ended, not the deployment. The
--waitflag controls how long the CLI waits. The server job keeps running. Check it withsf project deploy report. - The deployment is queued. Production allows one deployment to run at a time. If another deployment or a long Apex test run holds the queue, yours waits. Look at Setup > Deployment Status.
- Long test runs. A large org can take hours to run all local tests. Use
--asyncfor validation and poll the report, rather than holding a terminal open.
If the job is stuck and should not continue, cancel it:
sf project deploy cancel --job-id 0AfXXXXXXXXXXXXXXX --target-org prodWhy Quick Deploy is missing
A validation that finished with Succeeded should normally offer quick deploy. When it does not, check these conditions in order.
- Did the validation actually succeed? A failed or canceled job never offers quick deploy. Confirm the status in the report.
- Was it a validation? Quick deploy applies to a validation-only deployment. A real deployment has already saved its changes, so there is nothing to promote.
- Did tests run? A validation run with
NoTestRunhas no test results to reuse. Run it again withRunLocalTests,RunAllTestsInOrg, orRunSpecifiedTests. - Did coverage requirements pass? The validation must meet the coverage rules for the test level you chose.
- Is it too old? A validation stays eligible for 10 days after it completes. After that, validate again.
- Is it the same org? The validation ran against one target org. You cannot quick deploy it to another.
- Did the org change since? Another deployment to the same org, especially one touching the same components, can make the earlier validation ineligible. Treat any change to the target between validation and quick deploy as a risk and re-validate if the option disappears.
- Do you have permission? The user needs permission to deploy metadata, such as Deploy Change Sets or Modify Metadata, plus API access. A user without them sees no quick deploy action.
The 10-day window and the test-level requirement come from Salesforce documentation. Release notes occasionally refine the rules, so check the current documentation for your org's release.
Failures during the quick deploy itself
A quick deploy can still fail even when the button or command is available. It skips tests but it still saves components.
- Another deployment holds the queue. Wait for it to finish, then retry.
- The job ID is wrong. A typo, or the ID of a real deployment, returns an error. Copy the ID from the validation report.
- Org state changed. If the quick deploy reports that the validation can no longer be used, validate again.
Quick deploy returns a new deployment job ID. Track that new ID, not the validation ID:
sf project deploy quick \
--job-id 0AfXXXXXXXXXXXXXXX \
--target-org prod \
--asyncThen check progress with sf project deploy report --use-most-recent --target-org prod.
A repeatable diagnosis routine
Use the same sequence each time, so you do not skip a step under release pressure.
- Get the report for the job ID.
- Sort the output into component, test, or coverage problems.
- Reproduce in a sandbox that resembles production.
- Fix the cause in source control, not in the target org.
- Run a new validation and record its new job ID.
- Confirm quick deploy is available before the release window opens.
Step 6 matters. Learning at the start of the window that quick deploy is unavailable removes the benefit of validating early.
Exercise
A validation with RunSpecifiedTests fails with a coverage warning for OrderTrigger at 0%, although the org-wide average is 82%. You listed only OrderServiceTest. What are two ways to fix it, and which problem class is this?
Show answer
This is a coverage failure. With RunSpecifiedTests, each class and trigger in the deployment needs at least 75% coverage from the tests you named, and a trigger with no coverage fails regardless of the org average. Either add the test class that exercises the trigger to --tests (for example OrderTriggerTest), or add test methods to OrderServiceTest that fire the trigger. Then run a new validation and use its new job ID.
Exercise
A validation succeeded 12 days ago. You run sf project deploy quick and it fails. Why, and what do you do?
Show answer
A validation stays eligible for quick deploy for 10 days after it completes, so this one has expired. Run a new validation with a test level that runs tests, wait for it to succeed, and run quick deploy with the new job ID.
Exercise
Your validation used --test-level NoTestRun and succeeded, but quick deploy is not offered. What is the cause and the fix?
Show answer
No tests ran, so there are no test results to reuse. Quick deploy requires a validation that ran tests and met coverage. Re-run the validation with RunLocalTests, RunAllTestsInOrg, or RunSpecifiedTests.