How Scratch Orgs Fit in the Package Development Workflow
Develop Your Package in a Scratch Org
When developing a package, it’s preferable to use a namespaced scratch org. A namespaced scratch org prepends scratch org metadata with the package namespace. This is true for both metadata you create in the scratch org, and any metadata you deploy to the scratch org.
To create a namespaced scratch org, use your Dev Hub org to create the scratch org. Before you create the scratch org:
- Ensure that the namespace you plan to use is already associated with your Dev Hub org.
- Specify the namespace in your sfdx-project.json file.
- Create a scratch org definition file and include any features, settings, or limits that your org needs.
When you create a scratch org both the namespace and ancestry information listed in sfdx-project.json file are pulled into the scratch org. The ancestry information, specified as ancestorId or ancestorVersion in your sfdx-project.json file, seeds the scratch org with manageability rules, and later warns you if you attempt to change metadata in a way that's incompatible with the specified ancestor version. This way, you learn of issues during development instead of during the creation of the next package version.
To create a namespaced scratch org that includes ancestor information in the scratch org, run this CLI command.
1sf org create scratch --target-dev-hub MyHub --definition-file config/project-scratch-def.jsonIf you don’t want the ancestor and manageability rules seeded into the scratch org, include the --no-ancestors flag when you create the scratch org.
When you are ready to create a new package version, see Create Versions of a Second-Generation Managed Package.
Test Your Package in a Scratch Org
When testing your package, create a scratch org that doesn’t have a namespace. Use the --no-namespace parameter when you create the scratch org.
1sf org create scratch --definition-file config/project-scratch-def.json --no-namespace --no-ancestorsAfter you create the scratch org, install the package into the scratch org, and begin testing.
Enable Data Cloud for Scratch Orgs
To use Data Cloud components in scratch orgs or to add these components to a package, Data Cloud for Scratch Orgs must be enabled. Log a case with Salesforce Partner Support and request that Data Cloud for Scratch Orgs be enabled on your Partner Business Org. Data Cloud for Scratch Orgs is only available to scratch orgs associated with the Dev Hub in your Partner Business Org.