Sub topic 2
Package directories and the default directory
Assume you know basic Salesforce metadata, can run sf commands, and can read JSON. This chapter focuses on how a Salesforce DX project selects source and controls org settings.
`packageDirectories` and the default directory
packageDirectories is an array in sfdx-project.json. Each entry maps a local folder to Salesforce metadata. The entry with "default": true is the default directory for commands that do not specify a package directory.
Generate a project and inspect its layout:
sf project generate --name my-project
cd my-project
ls -aA typical source-format layout is:
my-project/
├── sfdx-project.json
├── .forceignore
├── config/
│ └── project-scratch-def.json
└── force-app/
└── main/
└── default/
├── classes/
├── lwc/
└── objects/Metadata is stored under force-app/main/default. For example, Apex classes go in classes, and Lightning Web Components go in lwc. The CLI converts this source format to the metadata format required by Salesforce during deployment.
{
"packageDirectories": [
{
"path": "force-app",
"default": true
}
],
"name": "my-project",
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "61.0"
}Project-level settings
These fields apply to the project:
| Field | Purpose |
|---|---|
| `name` | Identifies the project locally |
| `sourceApiVersion` | Selects the Metadata API version for source operations |
| `sfdcLoginUrl` | Provides the default login host |
| `namespace` | Declares the package namespace, or remains empty for an unpackaged project |
Use a login URL that matches your environment. Production and developer orgs normally use https://login.salesforce.com; sandboxes use https://test.salesforce.com.
Controlling tracked files
.forceignore uses Gitignore-style patterns. It excludes matching files from source tracking, retrievals, and deployments.
# Ignore local profiles and test output
**/profiles/**
**/jsconfig.json
**/__tests__/**Keep source files that must be deployed outside these patterns. A wrong pattern can silently omit metadata.
Scratch org definition
A scratch org definition describes the temporary org that the CLI creates. It is separate from sfdx-project.json, but the project commonly stores it under config.
{
"orgName": "My Project Scratch Org",
"edition": "Developer",
"features": [],
"settings": {
"lightningExperienceSettings": {
"enableS1DesktopEnabled": true
}
}
}Exercise
Which directory does a command use by default when packageDirectories contains multiple entries?
Show answer
The entry whose default property is true.