Sub topic 14
Diagnosing common failures
This chapter assumes you have enabled Dev Hub, authorized it with the Salesforce CLI, and written a scratch org definition file. It shows how to find the cause when sf org create scratch fails.
Start with the failing layer
A scratch org creation request passes through four layers. Each layer has its own kind of failure.
Work down the diagram in order. Most failures are fixed in the first three steps.
Dev Hub not found
The CLI needs to know which org is your Dev Hub. If it can't find one, creation stops before any request is sent. Check what the CLI knows about, then set the default.
sf org list
sf config get target-dev-hub
sf config set target-dev-hub=my-hubYou can also name the hub for a single command with --target-dev-hub my-hub. If my-hub is missing from sf org list, or its connection is marked expired, log in again with sf org login web --set-default-dev-hub --alias my-hub.
Dev Hub not enabled, or user lacks access
If the CLI reaches the org but the org refuses the request, confirm two things. First, Dev Hub is switched on under Setup > Development > Dev Hub. Second, the logged-in user is a system administrator or has the permissions to create scratch orgs. Remember that you cannot turn Dev Hub off once it is on.
Definition file errors
The definition file is read twice. The CLI parses the JSON locally, and Salesforce then validates the contents. Check the syntax first.
python3 -m json.tool config/project-scratch-def.jsonIf this prints an error, fix the JSON. Typical causes are a trailing comma or a missing quote. If the syntax is fine, look at the contents. Salesforce rejects misspelled feature names, settings that don't match the chosen edition, and setting names that belong to a different API version.
Limit errors
Each Dev Hub has two caps. ActiveScratchOrgs limits how many orgs can exist at once. DailyScratchOrgs limits how many you can create in a rolling 24 hours.
sf limits api display --target-org my-hubRead the Remaining value for both entries. If ActiveScratchOrgs is at zero, delete orgs you no longer need. If only DailyScratchOrgs is at zero, deleting orgs does not help, because deleted orgs still count toward the daily total. You have to wait.
Quick reference
| Symptom | Likely cause | First check |
|---|---|---|
| No Dev Hub found | No default set, or the login expired | `sf org list` |
| Org refuses the request | Dev Hub not enabled, or missing permission | Setup > Dev Hub |
| Invalid feature or setting | Typo, or the wrong edition | The definition file |
| Limit exceeded | Active or daily cap reached | `sf limits api display` |
Exercise
Your teammate gets a limit error. sf limits api display --target-org my-hub shows ActiveScratchOrgs with 10 remaining but DailyScratchOrgs with 0 remaining. Will deleting old scratch orgs fix it, and why?
Show answer
No. The active cap has room, so the daily cap is the problem. Deleted orgs still count toward the rolling 24-hour total, so your teammate has to wait until the daily window frees up capacity.