Sub topic 3
Opening, Inspecting, and Logging In to a Scratch Org
Assume you have authorized a Dev Hub, created my-scratch, and set it as a CLI target. A scratch org is temporary, so use its alias rather than relying on its generated username.
Open and inspect the org
Use sf org open to launch the org in a browser. Use sf org display to inspect its username, instance URL, and authentication details. Use sf org list to see every org known to the CLI.
sf org open --target-org my-scratch
sf org display --target-org my-scratch
sf org listThe alias is local CLI metadata. It makes commands readable and avoids copying long usernames.
Move source to and from the org
Deploy project source to the scratch org, then retrieve changes made in the org:
sf project deploy start --target-org my-scratch
sf project retrieve start --target-org my-scratchSource tracking records changes between the local project and a scratch org. Resolve conflicting edits deliberately instead of overwriting work without inspection.
Manage lifetime and limits
Scratch orgs expire after their configured duration. Delete one when work is complete to release an active slot:
sf org delete scratch --target-org my-scratch --no-promptCheck Dev Hub limits before creating more orgs:
sf limits api display --target-org my-hubReview ActiveScratchOrgs for current capacity and DailyScratchOrgs for the daily creation allowance. Creation failures commonly result from expired authorization, an invalid definition file, unsupported features, or exhausted limits. Run sf org display, validate the JSON, and inspect the Dev Hub limits first.
Automation and advanced org setup
Interactive browser authorization is unsuitable for CI. Automation should use a non-interactive, securely stored Dev Hub credential supported by your CI provider, such as an access token or JWT-based authorization. Never commit credentials to the project.
An org shape describes important metadata and settings from an existing org. A scratch org snapshot captures a configured scratch org for repeatable creation. Use these features when a basic definition file cannot reproduce the environment, and keep snapshots aligned with the project’s supported Salesforce release.
Exercise
Which command shows whether the Dev Hub can create another scratch org?
Show answer
Run sf limits api display --target-org my-hub and inspect ActiveScratchOrgs and DailyScratchOrgs.