Strategies to successfully create scratch orgs

salesforcedxscratch-orgscratch-org-definition-filesf

Have noticed it can be very difficult to successfully create scratch orgs. Wondering if something I am doing is contributing that. Sometimes it works. Sometimes it doesn't.

I have tried both of these variations of the commands:

  1. sf org create scratch (never worked for me – ever)…
sf org create scratch  --alias scratch --wait 30 --set-default --duration-days 30 --definition-file config/project-scratch-def.json
  1. sfdx force:org:create (takes 5-10 attempts – perhaps affected by the lunar cycle?)
sfdx force:org:create -a scratch -w 30 -s -d 30 -f config/project-scratch-def.json

Here's my project-scratch-def.json…

{
  "orgName": "My Scratch Org",
  "edition": "Developer",
  "adminEmail": "[email protected]",
  "description": "2GP development",
  "hasSampleData": true,
  "features": ["EnableSetPasswordInApi", "MultiCurrency", "SalesUser"],
  "settings": {
    "businessHoursSettings": {
      "businessHours": [
        {
          "name": "Default",
          "active": true,
          "default": true,
          "timeZoneId": "America/New_York",
          "mondayStartTime": "08:00:00.000Z",
          "mondayEndTime": "18:00:00.000Z",
          "tuesdayStartTime": "08:00:00.000Z",
          "tuesdayEndTime": "18:00:00.000Z",
          "wednesdayStartTime": "08:00:00.000Z",
          "wednesdayEndTime": "18:00:00.000Z",
          "thursdayStartTime": "08:00:00.000Z",
          "thursdayEndTime": "18:00:00.000Z",
          "fridayStartTime": "08:00:00.000Z",
          "fridayEndTime": "18:00:00.000Z"
        }
      ]
    },
    "currencySettings": {
      "enableMultiCurrency": false
    },
    "lightningExperienceSettings": {
      "enableS1DesktopEnabled": true
    },
    "mobileSettings": {
      "enableS1EncryptedStoragePref2": false
    },
    "opportunitySettings": {
      "enableOpportunityTeam": true
    }
  }
}

Previously, I tried turning on Change Data Capture on the Opportunity object in the scratch file to find that metadata (PlatformEventChannelMember) isn't supported. I took it out and still have challenges.

Could my scratch definition file be causing my problems? Does turning on features and settings increase the likelihood of failure?

Any words of wisdom from more experienced Salesforce developers out there?

Best Answer

Suggested strategies:

  1. Limit the size of the scratch definition file. Fewer features and settings take less time reducing chances of a timeout.
  2. Increase the API timeout for sfdx-cli in ~/.sfdx/sfdx-config.json by adding "apiversionTimeout": 600 to change the default timeout from 2 to 10 minutes.
  3. Create a larger instance size by picking a higher-end edition like Enterprise will provide more resources for the scratch org creation process.
  4. Create the scratch org of peak hours.
  5. Increase the wait time with the -w argument
Related Topic