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
  • Create the scratch org definition file
You can create scratch orgs for different purposes, such as for feature development, for development of packages that contain a namespace, or user acceptance testing.
  1. 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 type, org shape, and other options. If you are developing or updating features for a package, then your scratch org definition file probably indicates a namespace.
    1sfdx force:org:create -f project-scratch-def.json
    Specify scratch org definition values on the command line using key=value pairs
    1sfdx force:org:create adminEmail=me@email.com edition=Developer username=admin_user@orgname.org
    Create 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 purpose. And it’s much easier to remember when issuing subsequent CLI commands.
    1sfdx force:org:create -f project-scratch-def.json -a MyScratchOrg
    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, so 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 --nonamespace
    Indicate 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 --setdefaultusername

    Indicate 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, username: scratchorg1488709604@acme.com

    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:

    1sfdx force:data:soql:query -q "SELECT ID, Name, Status FROM ScratchOrgInfo WHERE CreatedBy.Name = '<your name>' AND CreatedDate = TODAY" -u <Dev Hub org>

    If your name is Jane Doe, and you created an alias for your Dev Hub org called DevHub, your query looks like this:

    1sfdx force:data:soql:query -q "SELECT ID, Name, Status FROM ScratchOrgInfo WHERE CreatedBy.Name = 'Jane Doe' AND CreatedDate = TODAY" -u DevHub

    If that doesn’t work, create another scratch org and increase the timeout value using the --wait parameter.

  2. 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 // opens in Lighting Experience
  3. Push local project source to your scratch org.