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 deploy result. It covers the failures you will meet most often and how to find their cause.
Start with the full error
A failed command prints a short summary. The detail is in the result tables: component failures, with file name, line, and message, and test failures, with class, method, and stack trace. Read those first. Then check the status of the last job.
sf project deploy report --use-most-recentFor a script, add --json to any command to get the same detail in a parseable form.
A triage flow
Common failures
| Symptom | Likely cause | Fix |
|---|---|---|
| No default org, or the wrong org is used | `target-org` is not set, or it points to another org | Run `sf config list`, then pass `--target-org` explicitly |
| Expired access token | The authorization lapsed or the sandbox was refreshed | Run `sf org login web` again |
| Conflicts detected | The org and your project both changed the same component | Retrieve to take the org version, or deploy with `--ignore-conflicts` to keep yours |
| `Entity of type ... not found` on retrieve | A typo in the metadata name, or the component is missing from that org | Check the type and name, which are case-sensitive in some cases |
| `no CustomField named ... found` on deploy | A dependency is missing from the deployed set or the target org | Include the dependency, or deploy it first |
| Test failure or coverage below 75% | A test failed, or code lacks coverage | Fix the test, then rerun with the right `--test-level` |
| A file is ignored with no message | A `.forceignore` rule matches it | Review the rules in `.forceignore` |
Check the scope of the job
Many failures come from deploying a different set than you intended. Preview first.
sf project deploy preview --target-org my-sandbox
sf project deploy start --source-dir force-app --target-org my-sandbox --dry-runThe preview lists what would deploy, what would be deleted, and which components conflict. The dry run catches component and test errors without saving anything.
Resolve conflicts on purpose
Source tracking reports a conflict when a component changed in both places. Do not pass --ignore-conflicts by habit. Decide which version is correct first.
sf project retrieve preview --target-org my-sandbox
sf project retrieve start --source-dir force-app --target-org my-sandbox --ignore-conflictsThe second command overwrites local files with the org version. Commit or stash your local changes before you run it.
Recover from a stopped command
If the terminal reports a timeout, the deployment may still be running in the org. Resume it instead of starting a second one.
sf project deploy resume --use-most-recentExercise
A deploy to a sandbox fails with "Conflicts detected". You have local edits you want to keep, and the org version is out of date. What should you do before choosing a flag?
Show answer
Run sf project deploy preview to see which components conflict, and confirm that the org change is one you can overwrite. If it is, deploy with --ignore-conflicts. If you are unsure, retrieve first and merge the differences in Git.