Sub topic 3
Which orgs can be a Dev Hub and who can use it
Prerequisites
This chapter assumes you know what a Dev Hub does and how scratch orgs relate to it. It also assumes you can sign in to a Salesforce org and find your way around Setup. You don't need the Salesforce CLI yet, but one verification step near the end uses it.
By the end, you should be able to decide which of your orgs can be a Dev Hub. You should also be able to say which users can create scratch orgs against it.
Two separate questions
Two questions come up before you enable Dev Hub:
- Is this org eligible to be a Dev Hub?
- Which people will use it, and what do they need?
The first is about the org's type and edition. The second is about user permissions inside that org. Errors in either one produce confusing failures later, so it helps to settle both now.
Which org types can be a Dev Hub
A Dev Hub is a feature you switch on in an existing org. It is not a separate kind of org. These org types can enable it:
| Org type | Can be a Dev Hub? | Notes |
|---|---|---|
| Production org (Enterprise, Unlimited, Performance, and similar editions) | Yes | The usual choice for teams. |
| Developer Edition org | Yes | Free, and a good choice for learning and personal projects. |
| Trial org | Yes | Useful for evaluation. It expires like any trial, and its scratch orgs go with it. |
| Sandbox | No | Sandboxes can't act as a Dev Hub. |
| Scratch org | No | A scratch org can't create other scratch orgs. |
Editions and the exact set of supported types change over time. Check Salesforce's current documentation before you commit a team to a specific edition.
The edition also affects capacity. Larger editions get higher limits on active and daily scratch orgs. A later chapter covers how to read those limits. For now, remember that edition is a planning decision. Don't choose an org only because it is the one you already have open.
Production, Developer Edition, or trial?
Which one to pick depends on how long the work will last and who shares it.
- Production org. Choose this for a team that will keep working over time. Scratch orgs are tied to the Dev Hub, so a stable, long-lived Dev Hub avoids losing track of them. Other admins can also manage who has access.
- Developer Edition org. Choose this for learning, demos, and individual projects. It is free and doesn't expire if you keep logging in. Its scratch org capacity is lower than a large production org's.
- Trial org. Choose this for short evaluations only. When the trial ends, the Dev Hub goes with it, along with the scratch org records it tracked.
A common mistake is to enable Dev Hub in a personal Developer Edition org for a project the whole team depends on. When the person who owns that org leaves, the team loses its Dev Hub.
Enabling is a one-way change
Enabling Dev Hub is permanent. Once you turn it on, you can't turn it off again. Enabling it doesn't change your existing data or customizations. It only adds the objects and features that track scratch orgs, namespaces, and some package features.
Because of this, it is reasonable to enable Dev Hub in a production org. It adds new objects, but it doesn't alter your existing setup. Still, treat it as a decision, not a toggle to try out. If you only want to experiment, use a free Developer Edition org.
Who can enable Dev Hub
To turn on Dev Hub, you need to be a system administrator in the org, or have equivalent permissions to change Setup. If you can't see the Dev Hub setting, you likely lack permission or the org isn't eligible. Both cases look similar from the Setup menu.
Who can use a Dev Hub
Enabling Dev Hub doesn't automatically let every user create scratch orgs. A user must exist in the Dev Hub org, and must have the right permissions there. When someone runs sf org create scratch, the CLI signs in as that user in the Dev Hub and creates a record there. That record is what makes the scratch org count against the Dev Hub's limits.
There are two paths to access:
- System administrators can use the Dev Hub right away. This is why one-person setups, such as a personal Developer Edition org, work without any extra configuration.
- Other users need permissions granted in the Dev Hub org. The usual approach is a permission set assigned to those users.
The permission set for scratch org users typically grants:
- Object access to
ScratchOrgInfo(read, create, delete, and view all). This is the record that represents each scratch org request. - Object access to
ActiveScratchOrg(read, delete, and view all). This tracks scratch orgs that are currently alive. - The API Enabled system permission, because the CLI talks to the org over the API.
The exact permissions Salesforce recommends can change, so check the current "add Salesforce DX users" documentation when you build the permission set. Prefer a permission set over editing profiles. You can then assign and remove access without touching a profile that other people share.
Seeing the difference between "can enable" and "can use"
Consider a team of five developers and one administrator.
- The administrator enables Dev Hub in the production org. This needs admin rights.
- The administrator creates a permission set with the scratch org permissions and assigns it to the five developers.
- Each developer runs
sf org login web --set-default-dev-hubwith their own credentials. Authorization is per user, and each developer's CLI stores its own connection to the Dev Hub.
Scratch orgs created by developers show up against the shared limits. All five developers draw from the same pool of active and daily scratch orgs. If one developer leaves old scratch orgs running, the others hit the limit sooner.
Verifying that a Dev Hub works
After you authorize the Dev Hub with the CLI, you can check that the Dev Hub objects exist. Running a query against ScratchOrgInfo is a direct test. This example assumes the alias my-hub, which you create when you authorize the org in a later chapter:
sf data query --query "SELECT Id, Status FROM ScratchOrgInfo LIMIT 5" --target-org my-hubIf Dev Hub is enabled and your user has access, the query returns rows or an empty table. If it isn't enabled, you typically get an error saying that ScratchOrgInfo isn't a supported object. If your user lacks permission, you get an access or insufficient-privileges style error instead. The message tells you which of the two problems you have.
Common mistakes
- Trying to enable Dev Hub in a sandbox. The option isn't available. Choose a production, Developer Edition, or trial org.
- Using a scratch org as the Dev Hub. A scratch org can't be a Dev Hub. Authorize the org it came from.
- Assuming everyone with a login can create scratch orgs. Only users with the right permissions in the Dev Hub org can.
- Putting a team's Dev Hub in an org with a single owner. Pick an org the team controls.
- Using a trial org for long-lived work. The Dev Hub and its tracking records disappear when the trial ends.
Exercises
Exercise
A colleague wants to enable Dev Hub in their full-copy sandbox so they can test the feature before the team uses it. What do you tell them, and what would you suggest instead?
Show answer
A sandbox can't be a Dev Hub, so the setting won't be available there. They can test in a free Developer Edition org. Enabling Dev Hub there is permanent, but it carries no production risk.
Exercise
A developer is a user in the production Dev Hub but is not a system administrator. The command sf org create scratch fails with an access error, while sf data query against ScratchOrgInfo also fails. Dev Hub is already enabled. What is the most likely cause and the fix?
Show answer
The user lacks permissions in the Dev Hub org. Assign a permission set that grants access to ScratchOrgInfo and ActiveScratchOrg and enables the API Enabled system permission, then have the user try again.