Newer Version Available
Create Scratch Orgs
Before you create a scratch org:
- Set up your Salesforce DX project
- Authorize the Dev Hub org
- Create the scratch org definition file
-
Create the scratch org.
To Run This Command Create a scratch org for development using a scratch org definition file The scratch org definition defines the org edition, features, org preferences, and some other options. 1sfdx force:org:create -f project-scratch-def.jsonSpecify scratch org definition values on the command line using key=value pairs 1sfdx force:org:create adminEmail=me@email.com edition=Developer \ 2 username=admin_user@orgname.orgCreate a scratch org with an alias Scratch org usernames are long and unintuitive. Setting an alias each time you create a scratch org is a great way to track the scratch org’s function. And it’s much easier to remember when issuing subsequent CLI commands. 1sfdx force:org:create -f project-scratch-def.json -a MyScratchOrgCreate a scratch org for user acceptance testing or to test installations of packages In this case, you don’t want to create a scratch org with a namespace. You can use this command to override the namespace value in the scratch org definition file. 1sfdx force:org:create -f project-scratch-def.json --nonamespaceIndicate that this scratch org is the default CLI commands that are run from within the project use the default scratch org, and you don’t have to manually enter the username parameter each time. 1sfdx force:org:create -f project-scratch-def.json --setdefaultusernameSpecify the scratch org’s duration, which indicates when the scratch org expires (in days). The default is 7 days. Valid values are from 1-30. 1sfdx force:org:create -f config/project-scratch-def.json --durationdays 301sfdx force:org:create -f config/project-scratch-def.json -d 3Indicate the path to the scratch definition file relative to your current directory. For sample repos, this file is located in the config directory.
Stdout displays two important pieces of information: the org ID and the username.
1Successfully created scratch org: 00D3D0000000PE5UAM, 2 username: test-b4agup43oxmu@example.comIf the create command times out before the scratch org is created (the default wait time is 6 minutes), you see an error. Issue this command to see if it returns the scratch org ID, which confirms the existence of the scratch org:
1sfdx force:data:soql:query -q "SELECT ID, Name, Status FROM ScratchOrgInfo \ 2 WHERE CreatedBy.Name = '<your name>' \ 3 AND CreatedDate = TODAY" -u <Dev Hub org>This example assumes that your name is Jane Doe, and you created an alias for your Dev Hub org called DevHub:
1sfdx force:data:soql:query -q "SELECT ID, Name, Status FROM ScratchOrgInfo \ 2 WHERE CreatedBy.Name = 'Jane Doe' AND CreatedDate = TODAY" -u DevHubIf that doesn’t work, create another scratch org and increase the timeout value using the --wait parameter. Don’t forget to delete the malfunctioning scratch org.
-
Open the org.
1sfdx force:org:open -u <username/alias>If you want to open the scratch org in Lightning Experience or open a Visualforce page, use the --path parameter.1sfdx force:org:open --path one/one.app - Push local project source to your scratch org.