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.
- 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-orgTypically, 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 Salesforce DX uses cached authentication tokens.
- Open the scratch org you just created by running the command:
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
- Push the dreamforce-lwc project into the scratch org with this command:
sfdx force:source:pushIt 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.
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.
- Assign the permission set by running the command:
sfdx force:user:permset:assign -n Dreamhouse
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.
- Import the sample data into the scratch org by running this command.
sfdx force:data:tree:import --plan data/sample-data-plan.json
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.
- If your scratch org isn't already open, open it with this command:
- Next, open the DreamHouse app:
- In the App Launcher , find and open DreamHouse.
- Click the Properties tab and notice that there are twelve new properties.
- Click the Brokers tab and notice that there are eight new brokers.
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.