Skip to main content

Set Up Salesforce DX Tools

Learning Objectives

After completing this unit, you’ll be able to:
  • Describe how the model for traditional org development differs from modular package development.
  • Describe the key characteristics of a package.

Get Started with Source-Driven Development

Salesforce DX adds tools that streamline the entire development life cycle. It improves team development and collaboration, facilitates automated testing and continuous integration, and makes the release cycle more efficient and agile.

But Salesforce DX is so much more than just a set of tools! It provides an alternative to change set development, and shifts the source of truth from the org to your version control system (VCS). It shifts your development focus from org development to package development. To learn how to migrate your existing dev processes to the package development model, head over to the Package Development Model module.

But enough with the chit-chat. Are you ready to start getting hands-on? Let’s get started setting up your environment and introducing you to a few tools.

What’s a Scratch Org?

Many of the Salesforce DX tools enable you to use a type of org called a scratch org. A scratch org is a dedicated, configurable, and short-term Salesforce environment. Scratch orgs drive developer productivity and collaboration during the development process, and facilitate automated testing and continuous integration. You can use the CLI or Salesforce Extensions for VS Code to open your scratch org in a browser without logging in. You can spin up a new scratch org when you want to:

  • Start a new project.
  • Start a new feature branch.
  • Test a new feature.
  • Start automated testing.
  • Perform development tasks directly in an org.
  • Start from “scratch” with a fresh new org.

Although scratch orgs are meant to be disposable, the scratch org configuration files contain the real brawn. Through the configuration file, you can configure the scratch org with different Salesforce editions and with just the features and settings you want. And you can share the scratch org configuration file with other team members. That way, you all have the same basic org in which to do your development.

Do Scratch Orgs Replace Sandboxes?

No. Scratch orgs aren’t meant to be replications of sandboxes or production orgs. Due to their ephemeral nature (and maximum 30-day lifespan), scratch orgs are perfect for developing a new feature or customization or package. And they work great for unit testing and continuous integration. Sandboxes, which contain all the metadata of your production org, are still necessary for final user-acceptance testing, continuous delivery, and staging.

So far, so good? Read on...

Enable Dev Hub

A Dev Hub provides you and your team with the ability to create and manage scratch orgs. Scratch orgs are temporary Salesforce environments where you do the bulk of your development work in this source-driven development paradigm.

To get started with scratch orgs, you choose an org to function as your Dev Hub. While you can enable Dev Hub in any paid org, it’s always best to practice somewhere other than production. Instead, enable Dev Hub in a Developer Edition org or Trailhead Playground to use with this module. You can find your existing Trailhead playgrounds or create a new one by clicking your profile picture, then selecting Hands-On Orgs.

  1. Log into the org you’ve chosen as your Dev Hub.
  2. In Setup, enter Dev Hub in the Quick Find box and select Dev Hub.
  3. Click the button to enable Dev Hub.

You can also make any paid org your Dev Hub and grant access to developers. Get the details in the Salesforce DX Developer Guide.

Now that you have a Dev Hub org, let’s set up the rest of your Salesforce DX tools.

Salesforce CLI: Two For One Fun

Salesforce CLI is a bundle of two executables: sfdx and sf. We first launched sfdx to provide you the ability to develop and test your apps more easily on Salesforce Platform. But if you want to work across all Salesforce clouds, sfdx doesn’t provide all the commands you need. With sf, we're bringing together a cross-cloud set of commands that streamline how you build and deploy across Salesforce. 

This Trailhead module uses the sfdx executable in all its examples. Some of the sfdx commands have sf equivalents. We encourage you to try them out! See Get Started with Salesforce CLI Unification for more information about the sf executable. Topics include how to install it, how you can use the two executables together, and a mapping between equivalent commands.

Install Salesforce CLI

Use the Salesforce CLI to control the full application life cycle of your apps. You can easily create environments for development and testing, synchronize source code between your orgs and VCS, and execute tests.

See the Salesforce CLI Setup Guide for complete installation instructions.

  1. Install the CLI from
  2. Confirm the CLI is properly installed and on the latest version by running the following command from the command line.
    sfdx update
    You should see output like sfdx-cli: Updating CLI....

Here are some other helpful commands to get you started:

Command What You See
sfdx force --help All the available topics in the force namespace
sfdx commands All available commands

OK, you’re well on your way. Now let’s continue setting up the rest of the Salesforce DX tooling.

Log In to the Dev Hub

To get started, log in to the Dev Hub using the CLI, so you’re authorized to create scratch orgs. You can use sfdx auth:web:login to log in to various orgs, and we’ve provided some options to help you manage those orgs.

You can display help for any command. Help provides information on what the command does, describes each parameter, and lists the short and long versions of the parameters. Here's how to display help for the first command you'll run.
sfdx auth:web:login -h
sfdx auth:web:login --help
  1. To authorize the Dev Hub, use the web login flow:
    sfdx auth:web:login -d -a DevHub
    Adding the -d flag sets this org as the default Dev Hub. Use the -a flag to set an alias for the org (something catchy like DevHub). An alias is much easier to remember than the unique Dev Hub username. Important Important: Only indicate the -d flag for your Dev Hub. If you use it with a different org, you can’t create scratch orgs until you correctly identify the Dev Hub using the config:set command.

  2. Log in with your credentials.

    Once successful, the CLI securely stores the token along with the alias for the org, in this example, DevHub. You can close the Dev Hub org at any time.

You can close the Dev Hub and still create scratch orgs. However, if you want to open the Dev Hub org to look at active scratch orgs or your namespace registry, the alias comes in quite handy:

sfdx force:org:open -u DevHub

A Bit More on Org Management

It’s likely you have many orgs, including sandboxes and your production org. With the CLI, you can also log in to them using these commands. When you log in to an org using the CLI, you add that org to the list of orgs that the CLI can work with in the future.

Log In to Sandboxes

If you create an alias for the sandbox ( -a flag), you can reference it by this alias instead of its long and often unintuitive username.

For example:

sfdx auth:web:login -r -a FullSandbox
sfdx auth:web:login -r -a DevSandbox

If you don't know your org's login URL, you can find it on the My Domain Setup Page.



Remember, don’t use the -d flag when logging into a sandbox. If you do, the CLI thinks the org is your Dev Hub, and then you’ll see an error when you try to create a scratch org.

The Power of Aliasing

As you might imagine, aliasing is a powerful way to manage and track your orgs, and we consider it a best practice. Why? Let’s look at scratch org usernames as an example. A scratch org username looks something like Not easy to remember. So when you issue a command that requires the org username, using an alias for the org that you can remember can speed things up.

sfdx force:org:open -u FullSandbox
sfdx force:org:open -u MyScratchOrg
sfdx force:limits:api:display -u DevSandbox

View All Orgs

At any point, you can run the command sfdx force:org:list to see all the orgs you’ve logged in to. Adding the --all option provides you even more info.

Now you’re really ready to get going—let’s go build a new app with the Salesforce CLI and scratch orgs.

Keep learning for
Sign up for an account to continue.
What’s in it for you?
  • Get personalized recommendations for your career goals
  • Practice your skills with hands-on challenges and quizzes
  • Track and share your progress with employers
  • Connect to mentorship and career opportunities