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.

Which org to develop againstTwo steps in order. At each step, a yes follows the arrow to the org; a no drops to the next step. Step 1: if the goal is to learn or try out an idea, a Developer Edition org. Step 2: if the work starts from version control, fits in 30 days and the org can be thrown away, a scratch org created from a Dev Hub. If the answer is no at both steps, a Developer or Developer Pro sandbox.Step 2Step 1NoNoLearn ortry outan idea?DeveloperEditionFrom versioncontrol,disposable andwithin 30 days?Scratch orgfrom aDev HubDeveloper orDeveloper Prosandbox

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.

  1. Installation. She installs Salesforce CLI with the Windows installer, VS Code, the Salesforce Extension Pack and JDK 21.
  2. Inherited scripts. A team script calls sfdx force:apex:test:run. It still works, because both names are aliases.
  3. 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-url and the alias dev-ana.
  4. Continuous integration. Every change in the repository is tested in a new scratch org, created from the production Dev Hub.
  5. 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

  1. Install Salesforce CLI with one method only and verify the version.
  2. Uninstall sfdx (v7) if it is still installed and change continuous integration scripts to install sf (v2).
  3. Authorize each org with its My Domain URL and an alias.
  4. Configure the policies of the Salesforce CLI connected app, or create your own external client app.
  5. Choose the development org with the diagram’s two steps.
  6. Decide which org hosts the Dev Hub before enabling it.
  7. Check the default org before running anonymous Apex.
  8. Run Apex tests with coverage before handing over each change.

Official sources

Back to the knowledge base