Loading...
Loading...
Enable Dev Hub on a Salesforce org and view its scratch org allocation, using the Salesforce CLI (sf). Use when someone wants to turn on or enable Dev Hub, set up an org to create scratch orgs or second-generation (2GP) and unlocked packages, check whether Dev Hub is already enabled, see how many scratch orgs they can create (Active and Daily scratch org limits, remaining allocation), configure Dev Hub preferences such as packaging, org shape export, or scratch org snapshots, or list the active scratch orgs created from a Dev Hub. Enabling deploys the enableScratchOrgManagementPref setting, is irreversible, needs a System Administrator (ModifyAllData or ModifyMetadata), and does not work in sandboxes. DO NOT TRIGGER for creating or deleting individual scratch orgs, for switching the default org (use dx-org-switch), or for trial or org expiration dates (use dx-org-trial-expiration-check).
npx skill4agent add forcedotcom/sf-skills dx-org-devhub-configuresf org create scratchsf org delete scratchdx-org-switchdx-org-trial-expiration-checkScratchOrgInfoSELECT COUNT() FROM ScratchOrgInfoINVALID_TYPEDo not infer enablement fromalone: it reportssf org list limits/ActiveScratchOrgsrows even on orgs where Dev Hub is off, so limits show allocation but not enablement.DailyScratchOrgs
DevHubSettings.enableScratchOrgManagementPrefenableDevHubsfINSUFFICIENT_ACCESS./scripts/$0<skill_dir>bash "<skill_dir>/scripts/devhub.sh" <alias-or-username> # status: on? + allocation
bash "<skill_dir>/scripts/devhub.sh" # default org (target-org)
bash "<skill_dir>/scripts/devhub.sh" <org> --allocation # allocation only
bash "<skill_dir>/scripts/devhub.sh" <org> --enable # validate enabling (dry run)
bash "<skill_dir>/scripts/devhub.sh" <org> --enable --apply # actually enable (irreversible)
bash "<skill_dir>/scripts/devhub.sh" <org> --list-scratch # list active scratch orgs
bash "<skill_dir>/scripts/devhub.sh" <alias> --instance-url <url> --enable --apply # log in first, then enable
bash "<skill_dir>/scripts/devhub.sh" <url> # bare instance URL: log in to ithttps://my-domain.my.salesforce.com--instance-url <url>sf org login web --instance-url <url><skill_dir>--enable--apply--enable --applysf org login web--allocation--list-scratch--packaging--snapshots--shape--jsonbash "<skill_dir>/scripts/devhub.sh" …./scripts/$0--apply| Flag | Purpose |
|---|---|
| Show only the scratch org allocation (Active/Daily). |
| List active scratch orgs created from this Dev Hub. |
| Enable Dev Hub (deploys |
| Configure sub-preferences without (re)enabling the master switch. Pair with a pref flag. |
| |
| |
| |
| |
| Any |
| Actually deploy to the explicit org argument. Default for |
| Authenticate an org first via |
| Log in to a specific instance (My Domain, sandbox, or pre-release/scratch instance) with |
| Emit machine-readable JSON. |
| Exit |
| Show usage. |
--enable--enable --packaging --applytarget-orgtarget-dev-hubexamples/status-output.md--json--jsondevHubEnabledstatusallocationsuccessapplieddevHubVerifiedStatebash "<skill_dir>/scripts/devhub.sh" my-devhub --json
# {"org":"my-devhub","devHubEnabled":true,"status":"enabled", ... }--fail-if-disabled3ALERT:012sfjq3--fail-if-disabled--login--instance-url <url><url>https://my-domain.my.salesforce.com# Log in to a specific instance (My Domain / pre-release / sandbox), then enable:
bash "<skill_dir>/scripts/devhub.sh" my-alias \
--instance-url https://my-domain.my.salesforce.com --enable --apply
# Bare instance URL as shorthand — logs in to it, then reports status:
bash "<skill_dir>/scripts/devhub.sh" https://my-domain.my.salesforce.com
# Just authenticate an org (no other action):
bash "<skill_dir>/scripts/devhub.sh" my-alias --loginsf org login webmy-alias://--instance-url--instance-urllogin.salesforce.comsf org login device my-org could not query org (...)
To authenticate against https://my-domain.my.salesforce.com, run:
sf org login web --instance-url "https://my-domain.my.salesforce.com" --alias "my-org"
Or let this script log you in and continue in one step:
devhub.sh "my-org" --instance-url "https://my-domain.my.salesforce.com" --login
Then re-run. List existing logins with: sf org list# Detect Dev Hub (INVALID_TYPE error means OFF; a count means ON):
sf data query --query "SELECT COUNT() FROM ScratchOrgInfo" --target-org <org> --json
# Enable Dev Hub via the Tooling API (what the Setup toggle does; irreversible):
sf api request rest "/services/data/v47.0/tooling/sobjects/DevHubSettings/DevHub" \
--method PATCH \
--body '{"FullName":"DevHub","Metadata":{"enableScratchOrgManagementPref":true}}' \
--target-org <org>
# Or enable in the UI: Setup > Quick Find > "Dev Hub" > turn Enable Dev Hub On.
# View scratch org allocation:
sf org list limits --target-org <org> --json | jq '.result[] | select(.name|test("ScratchOrg"))'sfjqsf org login websf config set target-dev-hub <org>enablePackaging2--enable --packagingScratchOrgInfoActiveScratchOrgdx-org-switchdx-org-trial-expiration-check