Newer Version Available

This content describes an older version of this product. View Latest

Create Scratch Orgs

After you create the scratch org definition file, you can easily spin up a scratch org and open it directly from the command line.

Before you create a scratch org:

  • Set up your Salesforce DX project
  • Authorize the Dev Hub org
  • Create the scratch org definition file

You can create scratch orgs for different functions, such as for feature development, for development of packages that contain a namespace, or for user acceptance testing.

Delete any unneeded or malfunctioning scratch orgs in the Dev Hub org or via the command line so that they don’t count against your active scratch org allocations.

Tip

Indicate the path to the scratch definition file relative to your current directory. For sample repos and new projects, this file is located in the config directory.

Ways to Create Scratch Orgs

Create a scratch org for development using a scratch org definition file, give the scratch org an alias, and indicate that this scratch org is the default.

Specify scratch org definition values on the command line using key=value pairs.

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

Specify the scratch org’s duration, which indicates when the scratch org expires (in 1-30 days). The default duration is 7 days.

Specify the Salesforce release for the scratch org. During the Salesforce release transition, you can specify the release (preview or previous) when creating a scratch org. See Select the Salesforce Release for a Scratch Org.

If Scratch Org Creation Is Successful

Stdout displays two important pieces of information: the org ID and the username.

You can now open the org.

Troubleshooting Tips

If 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:

This example assumes that your name is Jane Doe, and you created an alias for your Dev Hub org called DevHub:

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