Sub topic 3
How the Project Drives Deploy and Retrieve Commands
Assume you know basic Salesforce metadata, can run sf, and can read JSON. The Salesforce CLI reads sfdx-project.json from the project root. Its packageDirectories entries tell the CLI where source lives.
Deploying and retrieving source
A deploy sends local source to an org. A retrieve copies metadata from an org into the project. These commands use the package directories and source format:
sf project deploy start --target-org my-org
sf project retrieve start --target-org my-orgThe default directory is the normal source location when no path is specified. The CLI converts source format, such as force-app/main/default/classes, into the metadata API representation required by the org.
Multiple package directories
A project can separate source into directories such as core and feature. Each entry needs a real path. One directory should normally have "default": true.
{
"packageDirectories": [
{ "path": "core", "default": true },
{ "path": "feature", "default": false }
],
"name": "my-project",
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "61.0"
}The CLI can deploy or retrieve a selected directory with a path or metadata filter. Keep related metadata together so package boundaries remain clear.
Packages, aliases, and dependencies
An unlocked package is a versioned unit of Salesforce metadata. Add package, versionName, and versionNumber to a directory:
{
"path": "core",
"package": "core-pkg",
"versionName": "Spring release",
"versionNumber": "1.0.0.NEXT",
"default": true
}packageAliases maps readable names to Salesforce package IDs. A feature package can then declare a dependency on a core package version. The CLI uses these relationships when creating package versions. Directory order does not replace a declared dependency, but placing foundational source first makes projects easier to understand and validate.
Troubleshooting configuration
- Invalid JSON: check commas, quotes, and braces.
- Missing default directory: mark exactly one suitable directory as default.
- Wrong path: confirm the directory exists and contains source.
- Deploy or retrieve misses files: inspect
.forceignoreand the selected directory. - Package errors: verify aliases, version numbers, and dependency names.
Exercise
Why can a deploy omit metadata that exists in the repository?
Show answer
The metadata may be outside the configured package directories, excluded by .forceignore, or excluded by the command's path or metadata filter.