[email protected]
Introduction to Scratch Orgs

  • What is Scratch Org?
  • How it is different from normal Salesforce Sandboxes / Developer Orgs
  • How to create Scratch Org
Time to Complete: 45 Minutes

  • Enable Experience Cloud on Playground 1
    • Go to setup --> search digital experiences -> select settings in quick find --> Enable Digital Experience --> save
  • Enable experience bundle on Playground 1
    • Go to setup --> search digital experiences -> select settings in quick find
      --> Enable ExperienceBundle Metadata API --> save
  • Create community on Playground 1
    • Go to setup --> search all sites in quick find --> New --> Customer Account Portal --> Get started --> name = dreamhouseportal --> Create --> In workspaces --> Administration --> Activate

Add the below package.xml to your project root
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
Execute the sfdx force:source:retrieve command to retrieve the related files
sfdx force:source:retrieve -x package.xml -u <playground-1>

  • Go to setup --> search account settings in quick find --> Allow users to relate a contact to multiple accounts --> save
  • Update the ContactController class
    • Go to developer console --> file --> open --> Classes --> ContactController --> replace with below snippet --> save
    • Retrieve the ContactController from the org using sfdx force:source:retrieve command
public class ContactController {
public static List<contact> getContacts(string searchKey){
string key = '%'+ searchKey +'%' ;
return [SELECT Id,Name FROM Contact WHERE Name LIKE :key ORDER BY Name LIMIT 50];
* Get Account Contact Relation
public static List<AccountContactRelation> getContactAcrs(string contactId){
return [SELECT Id,AccountId,Roles,IsActive,IsDirect,StartDate,EndDate FROM AccountContactRelation WHERE ContactId =: ContactId];

  • Open your playground 1
  • Setup --> Search Dev Hub in Quick find--> Enable Dev Hub
  • Run the below command to see scratch orgs available for you
sfdx force:limits:api:display -u <playground-1>
Developer Edition/Trailhead playground provides 5 active scratch orgs at any given point in time. Create up to 6 scratch orgs per day by deleting the used ones. Create multiple playgrounds as you need to get more scratch orgs

Use the sfdx force:org:create command to create a new scratch org
sfdx force:org:create --definitionfile config\project-scratch-def.json --setdefaultusername --setalias <scratchorgaliasyouwishtouse> --durationdays <1-30> -v <playgroundaliasfromwhichyouwanttocreate>
Scratch Orgs adopt source tracking API which helps track the changes in both the local project and your scratch org. No need to track the list of files you modified.

Use the sfdx forceinstall command to install dependencies.
sfdx force:package:install -p 04t6F000001ZL7yQAG -w 30 --apexcompile package --securitytype AdminsOnly --noprompt -u <so-alias>
sfdx force:package:install -p 04t5I000001ecttQAA -w 30 --apexcompile package --securitytype AdminsOnly --noprompt -u <so-alias>
sfdx force:package:install -p 04t6F000001D6LOQA0 -w 30 --apexcompile package --securitytype AdminsOnly --noprompt -u <so-alias>

Use sfdx force:source:status to check the status
sfdx force:source:status

Navigage to Setup Menu
Search for "All Sites" in the Quick Find
Click on New > Customer Account Portal > Get started > name = dreamhouseportal

Use the sfdx force:source:push command to deploy
sfdx force:source:push --forceoverwrite
Did that fail?... Yes, we expected it to fail! Let's tackle that in our next challenge.

Use the force:org:delete command to delete your created scratch org
sfdx force:org:delete --targetusername <so-alias>
Commit your changes to the repo.

Scratch _**_Orgs are an important tool in Salesforce DX. It enables the quick provisioning and revoking of an org. You will really see the power when it is combined with source tracking.
Copy link
On this page
Learning Objectives
Create dreamhouse community
Retrieve the community from the org
Enable contacts to multiple accounts setting
Enable DevHub
Create a new scratch org
Install your dependencies to your scratch org
Check the source status
Create community on Scratch Org
Deploy your local source project to the scratch org
Delete the scratch org