Set Up Your Salesforce Environment
- Enable your Dev Hub.
- Prepare your command line interface to use Salesforce CLI.
- Authorize Salesforce CLI to connect to your Dev Hub.
Tasha and her team need a way to build temporary Salesforce orgs so they can build and test new features. These are called scratch orgs. Dev Hub is a feature that lets you create and manage scratch orgs. Normally, you would enable the Dev Hub in a developer org, but for the hands-on-challenge you will create a Trailhead Playground and enable Dev Hub there.
Create a New Trailhead Playground & Get User Credentials
In order to move ahead with their plans, Tasha and her team need to enable Dev Hub in a Trailhead Playground.
Tasha and her team follow these steps to create a new Trailhead Playground.
- In any Hands-On Challenge, click the dropdown and choose Create a Trailhead Playground.
- After it has been created, use the Manage my hands-on orgs option from the same menu to edit its name, if desired.
- Get Playground credentials by following the steps in the Get Your Trailhead Playground Username and Password unit of the Trailhead Playground Management module (see link in the Resources section below).
Enable Dev Hub
Next, Tasha and her team follow these steps to enable Dev Hub.
- From Setup, enter Dev Hub in the Quick Find box and select Dev Hub.
- To enable Dev Hub, click Enable. Don’t change any of the other options.
Prepare Command Line Interface
Now that Tasha’s ready to create and use scratch orgs, she needs to connect developer tools, such as Salesforce CLI and CumulusCI, to her Dev Hub. After installing Salesforce CLI on her computer, she connects it to Dev Hub—enabled in her Developer org—and this authorizes the use of scratch orgs.
Once Salesforce CLI is connected, Tasha needs to install CumulusCI to gain the automation framework for developing and testing Salesforce projects.
Install the Salesforce Command Line Interface
Tasha and her team follow these steps to install the interface.
- Navigate to the Salesforce CLI home and download the Salesforce CLI version for your operating system. Open the downloaded installation file and step through the installation with the default settings selected.
- To confirm that Salesforce CLI is installed, open VS Code and choose Terminal→New Terminal. It will look something like this:
- In the command prompt, enter:
If Tasha installed Salesforce CLI while VS Code was running, she may need to restart VS Code. She’ll know Salesforce CLI is installed because the command returns a single line in the Terminal panel that starts with
@salesforce/cli and describes the version of Salesforce CLI that's installed.
Authorize Salesforce CLI to Connect to Dev Hub
Tasha and her team follow these steps to authorize Salesforce CLI access to a DevHub-enabled org. The authorization allows Salesforce CLI to securely store a token (a secure version of your username/password) along with the alias for the Salesforce org.
Suggestion: set the alias to CCIDevHub to match the example used throughout the Build Applications with CumulusCI trail. It's much easier to remember than your unique Trailhead Playground username.
- Open VS Code and go to the Terminal in the Panel.
- Type this web login flow command to log in and set an alias name for the org, such as CCIDevHub:
sf org login web --alias CCIDevHub
- This will open a browser to the Salesforce login page. Log in using the username and password for the Trailhead Playground org in which you enabled Dev Hub.
- When prompted to “Allow Access” for Salesforce CLI, click the Allow button.
- Back in VS Code, verify you can now log into the org by typing this command:
sf org open --target-org CCIDevHub
If successful, a browser window opens to the org's Setup page. Tasha can now work in the org using Salesforce CLI commands, so she can close the browser window at any time.