Sub topic 15
Troubleshooting common retrieve and deploy failures
This chapter assumes you can authorize an org, retrieve and deploy with sf, and read a manifest. It covers how to read a failure, then the errors you will meet most often and what fixes each one.
How a failure is reported
Most failures fall into one of four stages. Knowing the stage tells you where to look.
- Before anything is sent. The CLI cannot find a project, an org, or the files you named.
- Conflict check. Source tracking finds that the same component changed both locally and in the org.
- Server-side validation. The org rejects components because of a missing dependency, a bad field, or an invalid value.
- Test and coverage phase. The components are valid, but Apex tests fail or coverage is too low.
Failures before the org is contacted
Not inside a project
Commands such as sf project deploy start read sfdx-project.json to learn your package directories. If you run them from another folder, the CLI reports that the command must run from within a Salesforce project directory. Change into the project root, or the folder below it, and run it again.
Unknown or expired org
Messages such as "No authorization information found for my-sandbox" mean the alias does not exist on this machine, or the stored token no longer works. List what the CLI knows and check the default:
sf org list
sf config get target-org
sf org display --target-org my-sandboxIf the org shows as expired or disconnected, authorize again with sf org login web --alias my-sandbox. Auth files are stored per machine, so a CI runner needs its own login.
Nothing to deploy or retrieve
"No source-backed components present in the package" means your selection resolved to zero components. The usual causes are:
- A wrong
--source-dirpath, or a directory outside everypackageDirectoriesentry insfdx-project.json. - A
.forceignorepattern that matches everything you selected. - A
--metadataname with a typo, such asApexClass:AcountService. - A manifest whose type names or member names do not match the org.
Run a dry run to see what the CLI would send without changing the org:
sf project deploy start --source-dir force-app --target-org my-sandbox --dry-runIf the component list is empty or smaller than expected, check .forceignore first. Remember that .forceignore also filters retrieves, so a retrieved file can seem to vanish.
Conflicts
For orgs with source tracking (scratch orgs and tracking-enabled sandboxes), the CLI compares each component against the last synced state. If a component changed locally and in the org, a deploy or retrieve stops and lists the conflicts. This protects you from silently overwriting a teammate's change made in Setup.
Preview first so you can decide which side wins:
sf project deploy preview --target-org my-sandbox
sf project retrieve preview --target-org my-sandboxThen pick one:
- Keep the org version: retrieve, then merge in Git.
- Keep your local version: deploy with
--ignore-conflicts. - Keep the org version and discard local edits: retrieve with
--ignore-conflicts.
sf project deploy start --source-dir force-app --target-org my-sandbox --ignore-conflictsProduction and sandboxes without tracking have no conflict detection at all. In those orgs, "deploy succeeded" does not mean you kept a colleague's change.
Component failures from the server
When the org rejects a component, the deploy output lists each failure with the component name, a line number, and a message. Common messages and their causes:
| Symptom | Likely cause | Fix |
|---|---|---|
| "Invalid reference" or "no such column" | A field, object, or class that the component uses is not in the target org | Deploy the dependency in the same job, or add it to the manifest |
| "Entity of type 'X' named 'Y' cannot be found" on retrieve | Typo, or the component does not exist in that org | Check the name in the org, or use a wildcard to list it |
| "Duplicate value found" or "already exists" | A component with the same name exists with different identifiers | Retrieve the org version, then reconcile |
| "Cannot delete component, it is referenced" | A destructive change targets a component still in use | Remove the references first, or delete in a later step |
| Version or feature errors | The manifest or `sourceApiVersion` is newer than the org supports, or a required feature is off | Match the API version to the org and enable the feature |
Order problems are common. A page layout that references a field fails if the field is not in the target org yet. Deploying the whole change set together resolves most of these, because the server works out the dependency order itself.
To see failures in a script-friendly form, use JSON output:
sf project deploy start --manifest manifest/package.xml --target-org my-sandbox --json \
| jq '.result.details.componentFailures'Test and coverage failures
A deploy that passes component validation can still fail in the test phase.
- Failing tests. One or more Apex tests failed. Fix the test or the code. Check whether the test depends on data that exists only in another org.
- Coverage too low. Deploying Apex to production requires 75% overall coverage, and each trigger must have some coverage. Add tests or choose a different scope.
- Wrong test level. With
--test-level RunLocalTests, all non-managed tests run. This takes longer thanRunSpecifiedTests, and it exposes failing tests that have nothing to do with your change.
Test levels also affect quick deploy. You can only quick-deploy a validation that ran tests, and the validation expires after 10 days. If the job ID is not accepted, run sf project deploy validate again.
sf project deploy validate --manifest manifest/package.xml --target-org production --test-level RunLocalTestsTimeouts, stuck jobs, and cancellation
The CLI waits for a deploy for a fixed time (set with --wait). When it stops waiting, the deployment keeps running in the org. The CLI exit does not mean failure.
sf project deploy report --use-most-recent
sf project deploy resume --use-most-recent
sf project deploy cancel --use-most-recent- Use
reportto read the current state without attaching. - Use
resumeto keep watching, and get the final result. - Use
cancelonly when you are sure you want the job stopped. A canceled job does not roll back components that are already saved only if the deployment was not atomic. Deployments are all-or-nothing by default, so a canceled job leaves the org unchanged.
Also check Setup > Deployment Status in the org. It shows jobs started from any tool, and a job queued behind another deploy can look like a hang.
A repeatable approach
- Read the first error, not the last. Later errors often follow from it.
- Name the stage: setup, conflict, component, or test.
- Reproduce with the smallest selection, such as one
--metadataitem. - Use
--dry-runorvalidatebefore a real change to a shared org. - Keep
--jsonoutput in CI logs so failures are searchable.
Exercise
A teammate's deploy to a sandbox stops with a list of conflicts. You believe your local version is correct and the sandbox has no tracking-related edits you need. What do you run first, and what do you run to push your version?
Show answer
Run sf project deploy preview --target-org my-sandbox first to see which components conflict and in which direction. If your local version should win, run sf project deploy start --source-dir force-app --target-org my-sandbox --ignore-conflicts. Commit your work to Git first.
Exercise
A deploy to production prints "Timed out waiting for deploy" after the CLI stops. Is the deployment failed, and how do you find the final outcome?
Show answer
The deployment is not failed. The CLI only stopped waiting, and the job continues in the org. Run sf project deploy report --use-most-recent to see its status, or sf project deploy resume --use-most-recent to resume watching until it completes.