# org create scratch

Create a scratch org.

## Description for org create scratch

There are four ways to create a scratch org:

<ul><li>Specify a definition file that contains the scratch org options.</li><li>Use the --edition flag to specify the one required option; this method doesn't require a defintion file.</li><li>Use the --snapshot flag to create a scratch org from a snapshot. Snapshots are a point-in-time copy of a scratch org; you create a snapshot with the "sf org create snapshot" command.</li><li>Use the --source-org flag to create a scratch org from an org shape. Org shapes mimic the baseline setup of a source org without the extraneous data and metadata; you create an org shape with the "sf org create shape" command.</li></ul>

The --edition, --snapshot, and --source-org flags are mutually exclusive, which means if you specify one, you can't also specify the others.

For any of the methods, you can also use these flags; if you use them with --definition-file, they override their equivalent option in the scratch org definition file:

<ul><li>--description</li><li>--name (equivalent to the "orgName" option)</li><li>--username</li><li>--release</li><li>--admin-email (equivalent to the "adminEmail" option)</li></ul>

If you want to set options such as org features or settings, you must use a definition file.

You must specify a Dev Hub to create a scratch org, either with the --target-dev-hub flag or by setting your default Dev Hub with the target-dev-hub configuration variable.

## Aliases for org create scratch

`env:create:scratch`

## Flags

| Flag Name (Long)    | Flag Name (Short) | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ------------------- | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--admin-email`     | N/A               | **Type:** Value<br><br>Email address that will be applied to the org's admin user. Overrides the value of the "adminEmail" option in the definition file, if set.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `--alias`           | `-a`              | **Type:** Value<br><br>Alias for the scratch org.<br><br>New scratch orgs include one administrator by default. The admin user's username is auto-generated and looks something like <test-wvkpnfm5z113@example.com>. When you set an alias for a new scratch org, it's assigned this username.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `--api-version`     | N/A               | **Type:** Value<br><br>Override the api version used for api requests made by this command                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `--async`           | N/A               | **Type:** Boolean<br><br>Request the org, but don't wait for it to complete.<br><br>The command immediately displays the job ID and returns control of the terminal to you. This way, you can continue to use the CLI. To resume the scratch org creation, run "sf org resume scratch".                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `--client-id`       | `-i`              | **Type:** Value<br><br>Consumer key of the Dev Hub connected app.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `--definition-file` | `-f`              | **Type:** Value<br><br>Path to a scratch org definition file.<br><br>The scratch org definition file is a blueprint for the scratch org. It mimics the shape of an org that you use in the development life cycle, such as acceptance testing, packaging, or production. See <<https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_scratch_orgs_def_file.htm>> for all the option you can specify in the definition file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `--description`     | N/A               | **Type:** Value<br><br>Description of the scratch org in the Dev Hub. Overrides the value of the "description" option in the definition file, if set.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `--duration-days`   | `-y`              | **Type:** Value<br>**Default value:** `7 days`<br><br>Number of days before the org expires.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `--edition`         | `-e`              | **Type:** Value<br>**Valid Values:** `developer`, `enterprise`, `group`, `professional`, `partner-developer`, `partner-enterprise`, `partner-group`, `partner-professional`<br><br>Salesforce edition of the scratch org. Overrides the value of the "edition" option in the definition file, if set.<br><br>The editions that begin with "partner-" are available only if the Dev Hub org is a Partner Business Org.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `--flags-dir`       | N/A               | **Type:** Value<br><br>Import flag values from a directory.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `--json`            | N/A               | **Type:** Boolean<br><br>Format output as json.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `--name`            | N/A               | **Type:** Value<br><br>Name of the org, such as "Acme Company". Overrides the value of the "orgName" option in the definition file, if set.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `--no-ancestors`    | `-c`              | **Type:** Boolean<br><br>Don't include second-generation managed package (2GP) ancestors in the scratch org.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `--no-namespace`    | `-m`              | **Type:** Boolean<br><br>Create the scratch org with no namespace, even if the Dev Hub has a namespace.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `--release`         | N/A               | **Type:** Value<br>**Valid Values:** `preview`, `previous`<br><br>Release of the scratch org as compared to the Dev Hub release.<br><br>By default, scratch orgs are on the same release as the Dev Hub. During Salesforce release transition periods, you can override this default behavior and opt in or out of the new release.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `--set-default`     | `-d`              | **Type:** Boolean<br><br>Set the scratch org as your default org                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `--snapshot`        | `-s`              | **Type:** Value<br><br>Name of the snapshot to use when creating this scratch org. Overrides the value of the "snapshot" option in the defintion file, if set.<br><br>To view the names of the available snapshots for a given Dev Hub org, run the "sf org list snapshot" command.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `--source-org`      | N/A               | **Type:** Value<br><br>15-character ID of the org shape that the new scratch org is based on. Overrides the value of the "sourceOrg" option in the definition file, if set.<br><br>To view the names of the available org shapes for a given Dev Hub org, run the "sf org list shape" command.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `--target-dev-hub`  | `-v`              | **Type:** Value<br>**Required**<br><br>Username or alias of the Dev Hub org.<br><br>Overrides the value of the target-dev-hub configuration variable, if set.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `--track-source`    | `-t`              | **Type:** Boolean<br>**Default value:** `true`<br><br>Use source tracking for this scratch org. Set --no-track-source to disable source tracking.<br><br>We recommend you enable source tracking in scratch orgs, which is why it's the default behavior. Source tracking allows you to track the changes you make to your metadata, both in your local project and in the scratch org, and to detect any conflicts between the two.<br><br>To disable source tracking in the new scratch org, specify the --no-track-source flag. The main reason to disable source tracking is for performance. For example, while you probably want to deploy metadata and run Apex tests in your CI/CD jobs, you probably don't want to incur the costs of source tracking (checking for conflicts, polling the SourceMember object, various file system operations.) This is a good use case for disabling source tracking in the scratch org. |
| `--username`        | N/A               | **Type:** Value<br><br>Username of the scratch org admin user. Overrides the value of the "username" option in the definition file, if set.<br><br>The username must be unique within the entire scratch org and sandbox universe. You must add your own logic to ensure uniqueness.<br><br>Omit this flag to have Salesforce generate a unique username for your org.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `--wait`            | `-w`              | **Type:** Value<br>**Default value:** `5 minutes`<br><br>Number of minutes to wait for the scratch org to be ready.<br><br>If the command continues to run after the wait period, the CLI returns control of the terminal to you and displays the job ID. To resume the scratch org creation, run the org resume scratch command and pass it the job ID.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |

## Examples for org create scratch

Create a Developer edition scratch org using your default Dev Hub and give the scratch org an alias:

```shell
sf org create scratch --edition developer --alias my-scratch-org
```

Create a scratch org with a definition file. Specify the Dev Hub using its alias, set the scratch org as your default, and specify that it expires in 3 days:

```shell
sf org create scratch --target-dev-hub MyHub --definition-file config/project-scratch-def.json --set-default --duration-days 3
```

Create a preview Enterprise edition scratch org; for use only during Salesforce release transition periods:

```shell
sf org create scratch --edition enterprise --alias my-scratch-org --target-dev-hub MyHub --release preview
```

Create a scratch org from a snapshot called "NightlyBranch"; be sure you specify the same Dev Hub org associated with the snapshot. We recommend you increase the --wait time because creating a scratch org from a snapshot can take a while:

```shell
sf org create scratch --alias my-scratch-org --target-dev-hub MyHub --snapshot NightlyBranch --wait 10
```
