Newer Version Available

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

Create a Scratch Org Based on a Snapshot

The snapshot must belong to the Dev Hub that you’re using to create the scratch org. Create a scratch org definition file that references the snapshot. We recommend creating a definition file specifically for this purpose. Changing or deleting a scratch org has no effect on a snapshot.

Create the Scratch Org Definition File

The scratch org definition file is the blueprint for your scratch org. It’s likely that your snapshot includes all the required features and settings to configure the scratch orgs created from it.

Using our Dreamhouse scratch org as an example, let’s create a scratch org definition file called dhsnapshot-scratch-def.json that contains only two entries: orgName and snapshot, which is the name you gave the snapshot when you created it.

Be sure you use the snapshot option instead of edition in the scratch org definition file.

Important

1{
2  "orgName": "Salesforce",
3  "snapshot": "dhsnapshot"
4}

When creating the scratch org definition file, don’t include these options:

  • edition
  • features
  • hasSampleData
  • release
  • sourceOrg

Add Settings to the Scratch Org Definition File to Override Default Snapshot Settings

Some scratch org settings aren’t inherited from the org snapshot. In these cases, you can add these settings in the scratch org definition file to achieve the desired scratch org configuration when creating a scratch org from a snapshot.

This example scratch org definition file illustrates adding some scratch org settings, in the event that these settings weren’t inherited from the scratch org snapshot.

1{
2  "orgName": "Salesforce",
3  "snapshot": "dhsnapshot",
4  "settings": {
5    "activitiesSettings": {
6      "enableCalendarHomeLWC": false
7    },
8    "omniChannelSettings": {
9      "enableOmniSkillRouting": true
10      "enableOmniChannel": true
11    },
12    "experienceBundleSettings": {
13      "enableExperienceBundleMetadata": true
14    },
15    "oauthOidcSettings": {
16      "blockOAuthUnPwFlow": true
17    },
18    "mobileSettings": {
19      "enableS1EncryptedStoragePref2": false
20    },
21    "securitySettings": {
22      "lockerServiceNext": false
23    }
24  }
25}

Create the Scratch Org Based On Your Snapshot

It can take Salesforce longer to create a scratch org from a snapshot, so we suggest you increase the --wait value so the command doesn’t time out. Remember to set the --target-dev-hub flag to the same Dev Hub org associated with the snapshot.

For example:

1sf org create scratch --definition-file config/dhsnapshot-scratch-def.json \
2--alias dh-scratch-ci --wait 10 --target-dev-hub my-dev-hub

Success! Development and testing with scratch orgs just got a whole lot easier.

Determine the Release Version for the Resulting Scratch Org

Normally, a scratch org is created on the same release version as the Dev Hub org regardless of how the scratch org was created: using the standard method, an org shape, or a snapshot. However, during Salesforce Preview, a scratch org can be created on a different release version from the Dev Hub org, if the snapshot release version differs from the Dev Hub’s release version.

During the Salesforce release transition, release version differences can occur for these scenarios:

  • The Dev Hub org is on the current generally available Salesforce release, but the snapshot is created on the preview release version.
  • The Dev Hub has upgraded to the preview release, but the snapshot was created on the current release version.

In cases where the Dev Hub org and snapshot release versions differ, the resulting scratch org is created on the same release version as the snapshot, as illustrated in this table.

Dev Hub Release Version Snapshot Release Version Resulting Scratch Org Release Version
Current Current Current
Current Preview Preview
Preview Current Current
Preview Preview Preview

Snapshot Error Codes

See Scratch Org Error Codes for details.