Sub topic 1
What a Salesforce DX Project Is
A Salesforce DX project is a source-controlled directory that stores Salesforce metadata in a format designed for development. The Salesforce CLI reads the project through sfdx-project.json. This chapter assumes you know basic Salesforce concepts, have sf installed and authorized to an org, and can read JSON and use Git.
Prerequisites
- Salesforce orgs, metadata, Apex, and Lightning components
- Salesforce CLI (
sf) and an authorized org - Command-line and Git basics
- JSON syntax
Generating a Project and Touring the Layout
Create a project with the CLI:
sf project generate --name my-project
cd my-project
ls -aThe generated layout separates project configuration from source:
my-project/
├── .forceignore
├── config/
│ └── project-scratch-def.json
├── force-app/
│ └── main/
│ └── default/
│ ├── classes/
│ ├── lwc/
│ └── objects/
└── sfdx-project.jsonforce-app/main/default is the default package directory. Its subdirectories group metadata by type. For example, Apex classes go in classes, Lightning web components go in lwc, and custom objects go in objects.
Source Format and Metadata Mapping
Source format breaks Salesforce metadata into files and folders that work well with Git. Salesforce metadata format often represents the same components in a deployable package structure, sometimes using single XML files for complex components.
For example, an Apex class commonly appears in source format as:
force-app/main/default/classes/AccountService.cls
force-app/main/default/classes/AccountService.cls-meta.xmlThe CLI converts source format when it deploys or retrieves metadata. You usually work in source format and let sf handle the conversion.
What `sfdx-project.json` Does
The CLI searches the current directory and its parents for sfdx-project.json. This file identifies package directories and sets project-wide values such as the API version.
{
"packageDirectories": [
{
"path": "force-app",
"default": true
}
],
"name": "my-project",
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "61.0"
}The default directory is used when a command needs a package directory but no path is specified. A wrong path, invalid JSON, or missing default directory can prevent project commands from working.
Exercise
Where does a generated project normally store an Apex class, and what converts it for deployment?
Show answer
Store it under force-app/main/default/classes. The Salesforce CLI converts source format into the metadata format required by the org.