Development environment
What to install to develop on Salesforce: Salesforce CLI, Visual Studio Code with Salesforce Extensions, a Salesforce DX project and which org to use.
A developer joins a team that builds on Salesforce: what do they install, how do they connect it to an org (a Salesforce organization), and which org do they work against? This page answers in that order, with a private-banking example.
The pieces of the environment
Salesforce CLI
Salesforce CLI is Salesforce’s command-line interface (CLI). It creates and manages orgs, synchronizes source with them and installs packages. It runs on the developer’s machine or in a continuous integration (CI) system, which builds and tests code automatically.
It is installed with an installer (.exe on Windows, .pkg on macOS), with TAR files or with npm. Choose one method only: mixing two causes path issues that are hard to diagnose. On Windows, Salesforce recommends the command prompt or PowerShell, not Linux terminal emulators. sf --version verifies the installation.
sf and sfdx
The current executable is sf. Its version 2 has been generally available since 12 July 2023. On that day Salesforce stopped updating sfdx (v7), the previous CLI.
If sfdx version returns a version starting with sfdx-cli/7, the old CLI is still installed and has to be uninstalled before installing sf (v2). Afterwards, sfdx is an alias of sf, with the same commands and options (flags). The old colon-separated names, such as force:auth:web:login, still work as aliases. The reference documents each command under its current name: sf org login web.
Visual Studio Code and Salesforce Extensions
For Visual Studio Code (VS Code), Salesforce publishes Salesforce Extensions for Visual Studio Code. It installs as a bundle, the Salesforce Extension Pack, from the VS Code Marketplace or the Open VSX Registry. It provides tools for working with development orgs, Apex, Lightning Web Components, Aura components and Visualforce.
The extensions use Salesforce CLI behind the scenes, so it has to be installed anyway. Some features also need the JDK (Java Platform, Standard Edition Development Kit) 11, 17 or 21.
The pack includes Agentforce Vibes, an extension with AI (artificial intelligence). Agentforce Vibes IDE is the browser-based version of this environment: an IDE (integrated development environment) with everything installed, launched from Setup in a sandbox.
The Salesforce DX project
Salesforce DX (Developer Experience) is the tooling for developing from source. Code and metadata, the description of the org’s configuration, live outside the org. The source of truth is the version control system, not the org. Salesforce DX requires the API Enabled system permission (API, application programming interface).
A Salesforce DX project is a folder with a fixed structure and a configuration file, sfdx-project.json. It is created with sf template generate project, and code goes in the force-app folder by default. In VS Code, SFDX: Create Project does the same. SFDX: Create Project with Manifest adds a package.xml to retrieve from an org the metadata listed in it.
Connecting the environment to an org
Authorizing an org means logging in so the CLI can run commands against it. It is done once per org.
The easiest way is sf org login web --alias my-org. The command opens the browser, the user logs in and clicks Allow. The alias identifies the org in later commands, and --set-default makes it the default. The user needs the Approve Uninstalled Connected Apps permission, which admins have by default.
With no other flags, the command opens https://login.salesforce.com. For another address, pass the org’s My Domain login URL (Uniform Resource Locator) in --instance-url. The first line is the general format; the second, a sandbox’s:
https://MyDomainName.my.salesforce.com
https://MyDomainName--SandboxName.sandbox.my.salesforce.com
The same URL can be set in sfdcLoginUrl, inside sfdx-project.json. Salesforce recommends the one ending in my.salesforce.com, not the one in Lightning Experience, the Salesforce user interface (.lightning.force.com).
The org needs an external client app, the preferred option, or a connected app: the configuration that lets an external application connect to Salesforce. By default, the CLI uses a connected app named Salesforce CLI, whose tokens never expire. Salesforce recommends configuring its policies: 90 days or less for the refresh token and 15 minutes for the access token.
In VS Code, SFDX: Authorize an Org asks for a login URL, such as Sandbox, and an alias. The status bar shows the default org.
Which org to develop against
There are three usual options:
- Sandbox. A copy of the production org for development, testing and training. Developer and Developer Pro copy the metadata, without data; Partial Copy and Full also copy part or all of the data. They do not expire when logged into regularly.
- Scratch org. A disposable org, created from source and configurable with a definition file. It starts empty. It lasts 30 days at most, 7 by default, and cannot be restored after it expires.
- Developer Edition. A free org with many Enterprise Edition features. It is not refreshed from production and falls out of sync over time.
Source tracking keeps the local project and the org in sync. Scratch orgs have it on by default; Developer Edition does not have it.
Scratch orgs are created from a Dev Hub, the org that manages them. Dev Hub is enabled in production, in a Developer Edition or in a trial org, never in a sandbox. Once enabled, it cannot be disabled.
Step 1 separates learning from building. Salesforce presents Developer Edition as suited to learning and experimenting, not as a permanent development environment.
Step 2 requires all three conditions. If one is missing, the sandbox brings production’s metadata with no setup and keeps changes for longer than 30 days.
Two development models
Salesforce DX supports two models. Both keep the project in version control; they differ in how code is deployed, tested and released.
- Org development. Work happens against orgs without source tracking, such as sandboxes without it, a Developer Edition or production, and changes are retrieved and deployed directly.
- Package development. Code is organized into versioned packages and developed against source-tracked orgs, such as scratch orgs.
They can be blended in one project. Deployment and version control belong to Metadata and deployment.
Running Apex from the tools
Anonymous Apex is Apex code that is compiled and run without being saved in the org. sf apex run --file script.apex runs it from a file. Without --target-org, it runs in the default org. In VS Code, SFDX: Execute Anonymous Apex with Currently Open Editor runs the open file. The documentation’s example updates contacts: an anonymous script can change org data.
Apex tests run with sf apex run test. --class-names picks classes and --test-level RunLocalTests runs the local tests. By default, the command is asynchronous and returns a test run ID; --wait waits for the results. --code-coverage adds code coverage. The command requires the View All Data permission.
In VS Code, the Test view (the beaker icon) runs one method, one class or all tests.
Example: a new developer at a private bank
A private bank adds a developer to the team that maintains its org.
- Installation. She installs Salesforce CLI with the Windows installer, VS Code, the Salesforce Extension Pack and JDK 21.
- Inherited scripts. A team script calls
sfdx force:apex:test:run. It still works, because both names are aliases. - First assignment. A change to the client record page that will take two months. Step 1: it is not learning. Step 2: it does not fit in 30 days. She works in her Developer sandbox, authorized with
--instance-urland the aliasdev-ana. - Continuous integration. Every change in the repository is tested in a new scratch org, created from the production Dev Hub.
- Before handing over. She runs
sf apex run test --test-level RunLocalTests --code-coverage --target-org dev-ana.
When to use each org
The criterion that separates them is what the org is for and how long it must last.
| Org | Use it when | Do not use it when |
|---|---|---|
| Developer Edition | You need to learn or try out an idea. | It would be a project’s permanent environment. |
| Scratch org | The work starts from version control, the org is disposable and 30 days are enough. | You need production’s configuration without preparing it, or the work lasts longer. |
| Developer or Developer Pro sandbox | You need production’s configuration or the work lasts longer than 30 days. | The org needs an edition different from production’s. |
Before production
- Install Salesforce CLI with one method only and verify the version.
- Uninstall sfdx (v7) if it is still installed and change continuous integration scripts to install sf (v2).
- Authorize each org with its My Domain URL and an alias.
- Configure the policies of the Salesforce CLI connected app, or create your own external client app.
- Choose the development org with the diagram’s two steps.
- Decide which org hosts the Dev Hub before enabling it.
- Check the default org before running anonymous Apex.
- Run Apex tests with coverage before handing over each change.
Official sources
- Quick Start — Salesforce CLI Setup Guide (opens in a new tab)
- Install Salesforce CLI — Salesforce CLI Setup Guide (opens in a new tab)
- Move from sfdx (v7) to sf (v2) — Salesforce CLI Setup Guide (opens in a new tab)
- org login web — Salesforce CLI Command Reference (opens in a new tab)
- template generate project — Salesforce CLI Command Reference (opens in a new tab)
- apex run — Salesforce CLI Command Reference (opens in a new tab)
- apex run test — Salesforce CLI Command Reference (opens in a new tab)
- How Salesforce Developer Experience (DX) Tooling Changes the Way You Work — Salesforce DX Developer Guide (opens in a new tab)
- Create a Salesforce DX Project — Salesforce DX Developer Guide (opens in a new tab)
- Authorization — Salesforce DX Developer Guide (opens in a new tab)
- Authorize an Org Using a Browser — Salesforce DX Developer Guide (opens in a new tab)
- Scratch Orgs — Salesforce DX Developer Guide (opens in a new tab)
- Sandboxes — Salesforce DX Developer Guide (opens in a new tab)
- Select and Enable a Dev Hub Org — Salesforce DX Developer Guide (opens in a new tab)
- Installation Instructions — Salesforce Extensions for Visual Studio Code (opens in a new tab)
- Develop with Ease with Salesforce Extensions — Salesforce Extensions for Visual Studio Code (opens in a new tab)
- Create Project — Salesforce Extensions for Visual Studio Code (opens in a new tab)
- Salesforce Development Models — Salesforce Extensions for Visual Studio Code (opens in a new tab)
- Org Development Model — Salesforce Extensions for Visual Studio Code (opens in a new tab)
- Package Development Model — Salesforce Extensions for Visual Studio Code (opens in a new tab)
- Change or Open Your Default Org — Salesforce Extensions for Visual Studio Code (opens in a new tab)
- Use Anonymous Apex — Salesforce Extensions for Visual Studio Code (opens in a new tab)
- Write Apex Tests — Salesforce Extensions for Visual Studio Code (opens in a new tab)
- Overview — Agentforce Vibes IDE (opens in a new tab)
- Overview — Agentforce Vibes Developer Guide (opens in a new tab)
- Choose the Right Salesforce Org for the Right Job — Salesforce Developers Blog (opens in a new tab)