Sub topic 13
Deploying and Retrieving Without Tracking
This chapter assumes you have a Salesforce DX project with force-app, the sf CLI installed, and an authorized org. It also assumes you know what source tracking records, as covered earlier.
Why tracking is missing in some orgs
Scratch orgs and some sandboxes support source tracking. Production orgs, and sandboxes where tracking is not enabled, do not. In an untracked org, the CLI has no revision history to compare against. It cannot work out which components changed, so a bare sf project deploy start has nothing to select and does not deploy anything useful.
You must say what to move. The CLI gives you three ways to do that.
Three ways to select source
sf project deploy start --target-org my-sandbox --source-dir force-app/main/default/classes
sf project deploy start --target-org my-sandbox --metadata ApexClass:MyClass
sf project deploy start --target-org my-sandbox --manifest manifest/package.xml| Flag | Selects | Best for |
|---|---|---|
| `--source-dir` | Every component under a file or folder | Moving one feature folder |
| `--metadata` | Components by type and name | Moving one or two named components |
| `--manifest` | Components listed in a `package.xml` | Repeatable, reviewable releases |
You can repeat --source-dir and --metadata to select several items in one command.
A manifest is a package.xml file that lists metadata types and member names:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>MyClass</members>
<members>MyClassTest</members>
<name>ApexClass</name>
</types>
<version>62.0</version>
</Package>Because a manifest is a file, you can commit it to Git. That makes a release repeatable and reviewable in a pull request.
Retrieving without tracking
Retrieve uses the same flags. Without tracking, the CLI retrieves what you name, and it overwrites the local copy of those files.
sf project retrieve start --target-org my-sandbox --metadata ApexClass:MyClass
sf project retrieve start --target-org my-sandbox --manifest manifest/package.xmlGit is your safety net here. Commit or stash your work before a retrieve, then use git diff to see exactly what the org changed.
Keep unwanted files out
A .forceignore file still applies. It lists patterns for files that the CLI skips on deploy and retrieve. This matters more without tracking, because you select by directory and a directory can contain files you never want in the org.
**/jsconfig.json
**/.eslintrc.json
**/__tests__/**Common errors
- Nothing deployed or an error about no source to deploy: you ran the command with no selection flag against an untracked org. Add
--source-dir,--metadata, or--manifest. - A dependency is missing in the target org: you selected a component that refers to another one, such as a field used by a class. Add the dependency to your selection.
- A local edit disappeared after a retrieve: the retrieve overwrote it. Restore it from Git.
- A component you deleted locally is still in the org: a normal deploy does not remove it. Deletions need a destructive changes manifest, which later chapters on deletes cover.
A safe routine
- Retrieve the components you plan to change.
- Review the diff in Git and commit.
- Make your edits.
- Deploy the same selection, ideally from a manifest.
Exercise
You run sf project deploy start --target-org prod in a project, and the org has no source tracking. Why is this not enough, and what are three ways to fix the command?
Show answer
Without tracking the CLI cannot compute which components changed, so it needs an explicit selection. Add --source-dir <path>, --metadata <Type:Name>, or --manifest <package.xml>.