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
In a nutshell
  • 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 start and sf project retrieve start move source; sf apex run test runs 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.

Git repositoryScratch orgsf org create scratchBuild and testDeploysf project deploy start

How it works

Salesforce DX building blocks

PiecePurpose
Dev HubThe org (usually production) that creates and manages scratch orgs and packages
Scratch orgA temporary, configurable org built from a definition file; expires after 7 days by default, up to 30 days
project-scratch-def.jsonEdition, features and settings for a scratch org
sfdx-project.jsonProject config: package directories and API version
Org shapeBuilds scratch orgs that mimic the features of a source org
Scratch org snapshotCaptures a prepared scratch org so new ones can be created from it quickly
Unlocked packagesVersioned, modular metadata for your own orgs

Salesforce CLI (sf) commands

CommandWhat it does
sf org login webAuthorize an org in the browser
sf org create scratch -f config/project-scratch-def.json -a devCreate a scratch org
sf project deploy startDeploy local source to an org
sf project retrieve startRetrieve metadata from an org to the project
sf apex run testRun Apex tests
sf apex run --file script.apexRun anonymous Apex
sf data import treeLoad sample data from JSON files
sf org openOpen the org in a browser

The older sfdx force:... commands were replaced by sf commands.

Editors

ToolNotes
VS Code + Salesforce Extension PackMain desktop IDE: deploy and retrieve, run tests, Apex Replay Debugger, LWC tools, Agentforce for Developers
Code BuilderVS Code in the browser, preconfigured with the extensions
Developer ConsoleIn the org: Execute Anonymous, logs, checkpoints, query editor, test runs, edit classes and pages

Developer Console features

FeatureUse
Execute AnonymousRun a snippet of Apex once, in the current user's context
Logs tabOpen debug logs, filter by category and view the execution log
Query EditorRun SOQL and SOSL; Query Plan shows whether a query is selective
CheckpointsInspect variable values at chosen lines in a heap dump
TestsRun test classes and view coverage

Sandboxes versus scratch orgs

NeedChoose
Short-lived org for one feature, built from sourceScratch org
Copy of production metadata for integration testingDeveloper or Developer Pro sandbox
Production-like data for performance or UATPartial 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.

Exam tip

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 start and sf project retrieve start move source; sf apex run test runs 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.
Watch out

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 run from 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.