Newer Version Available

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

Create a Package Version Based on a Scratch Org Snapshot

If the dependent package your base package requires is stable, you can reduce the end-to-end package version creation time by creating a scratch org snapshot.

If you haven’t reviewed When to Use Scratch Org Snapshots in Package Development, review that topic before continuing.

There’s more than one workflow you can follow when creating a package version based on a scratch org snapshot. You can start by creating a scratch org, you can build your own scratch org definition file, or you can choose to use org shape to create a new scratch org. Whichever path you choose, after the scratch org is created, you install all the dependent packages into it, and then take a snapshot of the scratch org.

Sample Workflow

This workflow uses an org shape to create the initial scratch org where you’ll install the stable dependent packages, and then create a scratch org snapshot to create a package version.

  1. Create the org shape.
    1sf org create shape --target-org source-org1
  2. Create a scratch org definition file that indicates the shape’s source org.
    1{
    2  "orgName": "Salesforce",
    3  "sourceOrg": "00DB1230400Ifx5"
    4}
  3. Create a scratch org using the org shape.
    1sf org create scratch --duration-days 30 --no-namespace --no-ancestors --definition-file config/scratch-def-with-shape-id.json --alias dev1-with-shape

    If your default Dev Hub org isn’t the one that owns the org shape, indicate it on the command line.

  4. Install the dependent packages.
    1sf package install --package 04txx --target-org dev1-with-shape
  5. Create a snapshot of the scratch org.
    1sf org create snapshot --name dhsnapshot --source-org dev1-with-shape --target-dev-hub dev-hub
  6. Create a new scratch org definition file and specify the snapshot name, then save the file.
    1{
    2  "orgName": "Salesforce",
    3  "snapshot": "dhsnapshot"
    4}
  7. Create a package version using the org snapshot. This command is specifying the scratch org definition file that contains the snapshot information in it.
    1sf package version create --package hc-ext1 --code-coverage --installation-key-bypass --async-validation --definition-file
    2scratch-def-with-snapshot-id.json