2

I'm hoping people can add comments about best practices they have found for making their SFDX scratch orgs mimic their target orgs.

My specific question is: How should I configure my project-scratch-def.json to best replicate my hub org. Are there any differences I should make to target a sandbox? My goal is to have my scratch org match as closely as possible the hub so that tests that pass in scratch pass in production and tests that fail in scratch fail in production.

I assume the "orgName" and "edition" should match the Organization Name and Organization Edition found under Setup > Company Information from the target org.

I'm less clear what values should be provided for "orgPreferences" and "features".

Here's a page with all of the options you can specify in the scratch org definition file: https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_scratch_orgs_def_file.htm

3

orgPreferences and features should ideally be configured with the same parameters as you have in production. For example, if you're using Territory Management, make sure you include that as an option, since you can't enable it later. Unfortunately, if you're not a totally new org just starting on DX, that means you'll have to discover which features you have enabled, which may require a lot of hunting around for settings and/or trial and error.

However, you will eventually be able to use the Org Shape feature to just copy the permissions directly from the org and deploy it to your scratch orgs. However, it's still a pilot, as far as I can tell, so you'll have to sign up for this feature if you want it, or wait until it goes GA (typically takes a release or two for pilots to make it to beta, but it may also never materialize). If you need a way to do this now, trial and error or the pilot are your two choices.

You'll have to basically look at the feature in the documentation, figure out what they're talking about, find the relevant setting in Setup, and then, if enabled, add it to your config file. Expect this to take a few days. If you're not on the pilot, there is no magical way to get at all this configuration in one place.

Once you start using Packaging 2.0 (2GP), you can choose to create different scratch orgs for different packages, thus minimizing the scratch org creation time. However, again, this will take time to build the packages and then determine the dependent features. There's no shortcut to this, other than to actually apply work hours to this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.