Topics

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.

Enter the command cat config/project-scratch-def.json to see some of the options available:

Typically, the command completes in less than a minute. You
get two items in the output: the org ID and the username.

Notice that we didn’t get a password. This is because with Salesforce DX we use cached authentication tokens.

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

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.

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.

Enter the command:

sfdx force:user:permset:assign -n Dreamhouse

But 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.

Enter the command:

sfdx force:data:tree:import --plan data/sample-data-plan.json

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.

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!

Next, open the DreamHouse app:

Click
to open the App Launcher.

Click DreamHouse.

Click the Properties tab and notice that there are 12 new properties.

Click the Brokers tab and see that there are eight new brokers.

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).