Testing, Debugging, and Deployment · Topic 2 of 4
Salesforce DX, the Salesforce CLI and the Developer Console
Salesforce developer tools: Salesforce DX, source-driven development, scratch orgs, Dev Hub, sf CLI commands, Code Builder and the Developer Console.
- 4 min
- Salesforce DX: source is the truth, scratch orgs are temporary, the Dev Hub creates them.
- Scratch orgs default to 7 days and last at most 30.
sf project deploy startandsf project retrieve startmove source;sf apex run testruns tests.
What it is
Salesforce DX is Salesforce's approach to source-driven development: the source of truth is a version-controlled project, not an org. Developers build in temporary scratch orgs, keep metadata in Git and deploy with the Salesforce CLI.
The Developer Console is a browser tool inside the org for quick tasks: running anonymous Apex, reading debug logs and running queries.
How it works
Salesforce DX building blocks
| Piece | Purpose |
|---|---|
| Dev Hub | The org (usually production) that creates and manages scratch orgs and packages |
| Scratch org | A temporary, configurable org built from a definition file; expires after 7 days by default, up to 30 days |
project-scratch-def.json | Edition, features and settings for a scratch org |
sfdx-project.json | Project config: package directories and API version |
| Org shape | Builds scratch orgs that mimic the features of a source org |
| Scratch org snapshot | Captures a prepared scratch org so new ones can be created from it quickly |
| Unlocked packages | Versioned, modular metadata for your own orgs |
Salesforce CLI (sf) commands
| Command | What it does |
|---|---|
sf org login web | Authorize an org in the browser |
sf org create scratch -f config/project-scratch-def.json -a dev | Create a scratch org |
sf project deploy start | Deploy local source to an org |
sf project retrieve start | Retrieve metadata from an org to the project |
sf apex run test | Run Apex tests |
sf apex run --file script.apex | Run anonymous Apex |
sf data import tree | Load sample data from JSON files |
sf org open | Open the org in a browser |
The older sfdx force:... commands were replaced by sf commands.
Editors
| Tool | Notes |
|---|---|
| VS Code + Salesforce Extension Pack | Main desktop IDE: deploy and retrieve, run tests, Apex Replay Debugger, LWC tools, Agentforce for Developers |
| Code Builder | VS Code in the browser, preconfigured with the extensions |
| Developer Console | In the org: Execute Anonymous, logs, checkpoints, query editor, test runs, edit classes and pages |
Developer Console features
| Feature | Use |
|---|---|
| Execute Anonymous | Run a snippet of Apex once, in the current user's context |
| Logs tab | Open debug logs, filter by category and view the execution log |
| Query Editor | Run SOQL and SOSL; Query Plan shows whether a query is selective |
| Checkpoints | Inspect variable values at chosen lines in a heap dump |
| Tests | Run test classes and view coverage |
Sandboxes versus scratch orgs
| Need | Choose |
|---|---|
| Short-lived org for one feature, built from source | Scratch org |
| Copy of production metadata for integration testing | Developer or Developer Pro sandbox |
| Production-like data for performance or UAT | Partial Copy or Full sandbox |
A worked example
Every new scratch org in a CI pipeline spends 40 minutes installing three managed packages and loading reference data. The team creates one scratch org, installs and loads everything, and takes a scratch org snapshot. New scratch orgs are then created from the snapshot, ready in minutes. An org shape copies features, not installed packages or data, so it does not solve this problem.
When a question mentions version control, scratch orgs or CI, the answer is in Salesforce DX and the CLI. When it mentions running a quick snippet in the org, it is Execute Anonymous.
How the exam asks about this
- "Which org must be enabled to create scratch orgs?" A Dev Hub.
- "Deploy local source to an org from a terminal."
sf project deploy start. - "Check whether a SOQL query is selective." The Query Plan tool in the Developer Console.
What to remember for the exam
- Salesforce DX: source is the truth, scratch orgs are temporary, the Dev Hub creates them.
- Scratch orgs default to 7 days and last at most 30.
sf project deploy startandsf project retrieve startmove source;sf apex run testruns tests.- VS Code and Code Builder are the main IDEs; the Developer Console is for quick in-org work.
- Execute Anonymous runs Apex once as the current user.
Changes made directly in a scratch org are lost when it expires unless they are retrieved into the project and committed to version control.
Common mistakes
Treating a scratch org as a long-lived sandbox. It expires.
Using the Developer Console for team source control. It has no version control; use the CLI and Git.
Expecting an org shape to copy data or packages. It copies features and settings only.
Check yourself
What is the role of the Dev Hub?
It creates and manages scratch orgs and second-generation packages.
Which CLI command deploys local source to an org?
sf project deploy start.Where can you run a one-off snippet of Apex inside the org?
Execute Anonymous in the Developer Console, or
sf apex runfrom the CLI.
Topic 2 of 4 in Testing, Debugging, and Deployment
Test yourself on Testing, Debugging, and Deployment
The full Salesforce Platform Developer question bank has 645 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Salesforce. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.