Start tracking your progress
Trailhead Home
Trailhead Home

Set Up Salesforce DX

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 new 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 new 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 some new and some familiar tools.

What’s a Scratch Org?

Many of the new tools enable you to use a new 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 new 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, go ahead and enable Dev Hub in a Developer Edition org or Trailhead Playground to use with this module.

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

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

Install the Command Line Interface (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 DX Setup Guide for complete installation instructions.

  1. Install the CLI.
    Operating System Link to Installer
    Windows 32-bit
    Windows 64-bit
    Debian/Ubuntu 64

    Download the archive from one of the URLs in the manifest, extract the archive, then run the ./install script.

    Debian/Ubuntu x86

    Download the archive from one of the URLs in the manifest, extract the archive, then run the ./install script.

    Let’s make sure the CLI is properly installed and you know how to access online help for the commands.

  2. In a command window, enter sfdx.

    You’ll see something like this:

    Usage: sfdx COMMAND [command-specific-options]
    Help topics, type "sfdx help TOPIC" for more details:
    sfdx force # tools for the salesforce developer
    sfdx plugins # manage plugins
    sfdx update # update sfdx-cli


If you don’t see this type of response, enter sfdx update to ensure that you have the Salesforce DX plug-in and the latest bits.

Here are some other helpful commands to get you started:

Command What You See
sfdx force --help All the available topics
sfdx force:doc:commands:list All available commands

OK, you’re well on your way. Now let’s continue installing 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 force: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 force:auth:web:login -h
sfdx force:auth:web:login --help
  1. To authorize the Dev Hub, use the web login flow:
    sfdx force:auth:web:login -d -a DevHub

    Adding the -d flag sets this org as the default Dev Hub. Use the -a to set an alias for the org (something catchy like DevHub). An alias is much easier to remember than the unique Dev Hub username.



    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 option), you can reference it by this alias instead of its long and often unintuitive username.

For example:

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


Remember, don’t use the -d flag. 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 --verbose 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.