Create and Test Our Scratch Org

In this step, you create a scratch org, assign a permission set, and push sample data to the scratch org.

Note

Note

Your Dev Hub org edition determines how many scratch orgs you can create daily, and how many can be active at a given point. You delete an existing scratch org to free up an allocation with the sfdx force:org:delete command.

  1. Create a 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 Salesforce DX uses cached authentication tokens.

  2. Open the scratch org you just created by running the command:
    sfdx force:org:open

Because you set the scratch org as default using the -s flag, the system remembers stores the authentication token and uses it to log in for you. The -s flag saves you time from having to manually log in and remember passwords later.

Next, push the dreamhouse-lwc project you cloned in the last unit to the new scratch org.

Push Source Metadata to Scratch Org

  1. Push the dreamforce-lwc project 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. The terminal window displays the list of resources that successfully pushed.
    Image shows metadata being pushed into the scratch org

Assign a Permission Set to the DreamHouse App

The Dreamhouse app uses a permission set to provide access. Before you test the app, you need the permission set assigned. With Salesforce DX CLI, you have the ability to assign permission sets remotely.

  1. Assign the permission set by running the command:
    sfdx force:user:permset:assign -n Dreamhouse
    Image shows assigning permissions

To test the application, you need data in the scratch org. Push the sample data included in the dreamhouse-lwc project into the scratch org.

Import Test Data

Use force:data commands to manipulate records in your org through the command-line terminal window. To import data into an org, use the sObject Tree Save API.

  1. Import the sample data into the scratch org by running this command.
    sfdx force:data:tree:import --plan data/sample-data-plan.json
    Image shows importing sample data into the Org

You've successfully set up your scratch org with the dreamhouse-lwc project. You're now ready to test the application.

Test Your App in the Scratch Org

After pushing projects and data into a scratch org, its a good idea to check everything exists as expected.

  1. If your scratch org isn't already open, open it with this command:
    sfdx force:org:open
  2. Next, open the DreamHouse app:
    • In the App Launcher App Launcher icon, find and open DreamHouse.
    • Click the Properties tab and notice that there are twelve new properties.
       Dreamhouse app in the new Scratch Org
    • Click the Brokers tab and notice that there are eight new brokers.
      “Brokers” tab of Dreamhouse app

Congratulations! You used the Salesforce CLI to create a scratch org, assign a permission set, and push sample data.

You're now ready to begin developing new features in the DreamHouse application. Continue learning how to use Salesforce DX with other developer tools such as Visual Studio Code (VS Code) and build continuous integration (CI). Learn more about Salesforce DX in the Get Started with Salesforce DX trail.

Click Verify Step to confirm the scratch org was created and to earn the badge.

Keep learning for
free!
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