Sub topic 1
What Scratch Orgs Are and Why Teams Use Them
Prerequisites
This chapter assumes that you know the basics of Salesforce orgs and Setup, can use a terminal, and have the Salesforce CLI (sf) installed. You also need administrator access to an eligible Salesforce org and basic JSON knowledge for later chapters.
Scratch Orgs and Team Workflows
A scratch org is a temporary, configurable Salesforce org created from a definition file. It is isolated from production and usually expires after a short period. Developers use scratch orgs to build and test features without changing a shared development org.
A scratch org is different from a sandbox. A sandbox is a longer-lived copy or configuration of an existing org. A scratch org is disposable and created from source-controlled configuration.
Scratch orgs help teams keep environments consistent, review changes safely, and run repeatable tests. Their short lifetime also exposes setup assumptions that might remain hidden in a long-lived sandbox.
What a Dev Hub Does
A Dev Hub is the Salesforce org that owns scratch-org creation and tracking. The Salesforce CLI authenticates to the Dev Hub, requests a scratch org, and records that org under the Dev Hub’s limits. The Dev Hub does not become the scratch org, and enabling it does not convert an existing org into one.
Which Orgs and Users Qualify
Salesforce supports Dev Hub in production orgs, Developer Edition orgs, and eligible trial orgs. The exact availability can depend on the org type and Salesforce license. A system administrator enables the feature. Other users need the Dev Hub permissions required for the operations they perform, such as creating scratch orgs.
Enabling Dev Hub in Setup
In the intended Dev Hub org:
- Open Setup.
- Search for Dev Hub in Quick Find.
- Select Dev Hub.
- Select Enable Dev Hub and confirm.
Treat this as a deliberate org choice. After enabling it, verify that the CLI authenticates to this org rather than to a different production or sandbox org.
Checking Your Salesforce CLI
Run these commands before creating a project:
sf --version
sf org login web --set-default-dev-hub --alias my-hubThe first command confirms installation. The second opens a browser login and saves the authorized Dev Hub as my-hub. A common error is authenticating the wrong org, so check the username and org details before continuing.
Exercise
Why should a team use a scratch org instead of a shared sandbox for an isolated feature?
Show answer
A scratch org is temporary, configurable from source, and isolated from other developers' work.