Sub topic 2
What a Dev Hub does
This chapter explains the role of the Dev Hub org. It assumes you know what a Salesforce org is, can find your way around Setup, and have read the previous chapter on why teams use scratch orgs. You don't run any commands here. The later chapters do that.
The Dev Hub is a control org
A Dev Hub is a regular Salesforce org with the Dev Hub feature turned on. It doesn't hold your project's code or test data. Its job is to create scratch orgs and keep track of them.
When you run a scratch org command, the CLI doesn't build the org itself. It sends a request to the Dev Hub. The Dev Hub checks that you may create the org, checks that you are within your limits, and starts the build. Without an authorized Dev Hub, sf org create scratch can't run.
What the Dev Hub keeps track of
The Dev Hub is the system of record for every scratch org created through it. It stores:
- A record for each scratch org, including its status, edition, creation date, and expiration date.
- The identity of the user who created it.
- Counts used to enforce limits on active and daily scratch orgs.
Each scratch org record appears as a ScratchOrgInfo record in the Dev Hub. A related ActiveScratchOrg record exists only while the org is alive. When the org expires or you delete it, the active record goes away, and the history stays.
Why limits live here
Scratch orgs are meant to be short-lived and plentiful, but not unlimited. The Dev Hub applies two kinds of caps:
| Limit | What it controls |
|---|---|
| Active scratch orgs | How many scratch orgs can exist at the same time |
| Daily scratch orgs | How many can be created in a 24-hour period |
The caps depend on the Dev Hub's edition. A later chapter shows how to read them from the CLI. For now, remember that all your developers share the same pool, because the limits belong to the Dev Hub and not to a person.
Other things a Dev Hub is used for
Scratch orgs are the main reason to enable Dev Hub, but the same org also supports other Salesforce DX features:
- Registering namespaces for packages.
- Creating and managing second-generation packages.
- Org shape and scratch org snapshots, which are covered near the end of this tutorial.
Common misunderstandings
- The Dev Hub is not your development org. Don't build your project in it. Developers work in scratch orgs, and the Dev Hub stays stable.
- Deleting a scratch org doesn't delete your work. Your source lives in your project and version control. The scratch org is disposable.
- Many people can share one Dev Hub. Most teams use a single Dev Hub, often their production org, so that usage and limits are visible in one place.
Exercise
A teammate runs sf org create scratch and gets an error saying no Dev Hub is available. Based on this chapter, what is the cause, and which org does the request go to when it works?
Show answer
The CLI has no authorized Dev Hub to send the request to. When a Dev Hub is authorized, the CLI sends the request to it. The Dev Hub checks permissions and limits, creates the scratch org, and records it as a ScratchOrgInfo record.