trailhead

Create and Test Our Scratch Org

In this step, we create the scratch org to use during development. We create the scratch org with—you guessed it—the CLI, with the use of a config file. The DreamHouse app repository provides a few example config files. 

  1. Enter the command cat config/project-scratch-def.json to see some of the options available:
    {
      "orgName": "Dreamhouse",
      "edition": "Developer",
      "hasSampleData": "false",
      "settings": {
        "orgPreferenceSettings": {
          "s1DesktopEnabled": true,
          "selfSetPasswordInApi": true,
          "s1EncryptedStoragePref2": false
        }
      }
    }
  2. Next, use the following command to create the scratch org, set it as your default, and give it an alias:
    sfdx force:org:create -s -f config/project-scratch-def.json -a dreamhouse-org
    Typically, the command completes in less than a minute. You get two items in the output: the org ID and the username.

    Image shows creating a scratch orgNotice that we didn’t get a password. This is because with Salesforce DX we use cached authentication tokens.

  3. Let’s try this out. Enter the command:
    sfdx force:org:open

This command uses the Salesforce front door to automatically log in with our cached authentication token, so there’s no explicit need for us to know the password. Pretty cool, right?

At this point we have a brand-new empty scratch org. Next we populate it with the source we first pulled out of GitHub. For this, we use the source synchronization APIs, also available in the CLI.

Push Source Metadata to Scratch Org

  1. Let’s push all the local source into the scratch org with this command:
    sfdx force:source:push
    It takes a few moments, but all the metadata is pushed into the scratch org.
    Image shows metadata being pushed into the scratch org

Assign a Permission Set to the DreamHouse App and Import Test Data

At this point we’re close to being able to run the DreamHouse app. But when you look at the source that was pushed to the org, you see that the app uses a permission set to provide access. Before we can access the app, we need to assign that permset using the CLI.

  1. Enter the command:
    sfdx force:user:permset:assign -n Dreamhouse
    Image shows assigning permissionsBut wait a minute… we don’t have any of the DreamHouse app data in the org. Luckily, we do have sample data in our repository. Let’s use the CLI and the SObject Tree API to import this data into the org.

  2. Enter the command:
    sfdx force:data:tree:import --plan data/sample-data-plan.json
  3. Image shows importing sample data into the Org

Now that we’ve fully set up and configured our project, we’re ready to begin development.

Test Your App in the Scratch Org

We are almost there! All that's left is to try out the application.

  1. If your scratch org isn't already open, open it with this command:
    sfdx force:org:open
    Notice that you don’t have to log in!

  2. Next, open the DreamHouse app:
    • Click App Launcher icon to open the App Launcher.
    • Click DreamHouse.
    • Click the Properties tab and notice that there are 12 new properties.
       Dreamhouse app in the new Scratch Org

    • Click the Brokers tab and see that there are eight new brokers.
      “Brokers” tab of Dreamhouse app

Congratulations! You’ve quickly used Salesforce DX to create a development environment, complete with your application. 

From here you can begin developing new features in the DreamHouse app, and use Salesforce DX with other developer tools and processes like integrated development environments (IDEs), VCS, and continuous integration (CI). 

Learn more about Salesforce DX in the Get Started with Salesforce DX trail.

We won't check any of your setup. Click Verify Step to earn your badge.

retargeting