Sub topic 8
Scratch Orgs and Developer Edition Orgs
This chapter assumes you know what an org is, the difference between metadata and data, and that sandboxes are copies of a production org. You should also be comfortable running commands in a terminal. If any of that is unfamiliar, review the earlier chapters on orgs, org types, and sandboxes first.
By the end you will be able to describe what scratch orgs and Developer Edition orgs are, create a scratch org with the Salesforce CLI, and choose between the two for a given task.
Two orgs for building, not for running a business
Production orgs run a company's real work. Sandboxes copy a production org so teams can test against its configuration. Scratch orgs and Developer Edition orgs fill a different need: a place to build and learn that is not tied to any production org.
- A Developer Edition (DE) org is a free, long-lived org that anyone can sign up for. It has a fixed, small set of features and limits, and it is meant for learning and experimenting.
- A scratch org is a short-lived, disposable org that you create from a configuration file. It is meant for development and automated testing, and it is usually created through the Salesforce CLI.
Both are separate from your production org. Nothing you do in either one touches real customer data.
Developer Edition orgs
You get a Developer Edition org by signing up on the Salesforce developer site. The sign-up creates a new org with its own Org ID, its own My Domain, and its own username. Nobody else shares it with you unless you add users.
Key properties:
- Free and persistent. It does not expire as long as you keep using it. Salesforce can deactivate DE orgs that go unused for a long period, so log in occasionally.
- Fixed edition. The edition is Developer Edition, with lower limits than the paid editions. Storage and API request allowances are small, and only a few user licenses are included.
- Includes many platform features. You can build custom objects, fields, Apex code, Lightning components, and flows. Some features that need paid add-ons are unavailable or limited.
- Built by hand. You normally set it up through Setup clicks or deployments. It has no configuration file that recreates it from scratch.
- Sample data is minimal. You load your own test records.
Because a DE org persists, it is a good home for long-running experiments, for certification study, and for trying a feature before you raise it with your team.
Limits of a Developer Edition org
A DE org is not a copy of your production org, so it does not carry your company's metadata. It also cannot be refreshed from production the way a sandbox can. If you need production's configuration, use a sandbox. If you want a clean slate, use a scratch org.
Scratch orgs
A scratch org is created from a definition file, a JSON file that describes the org. The file names the edition, features, and settings you want. Because the org is built from that file, you can recreate the same org any number of times.
Key properties:
- Disposable. A scratch org has an expiration of 1 to 30 days. The default is 7 days. When it expires, it is deleted.
- Defined by configuration. The definition file is source-controlled with your project, so every developer gets the same starting point.
- Created on demand. Creation takes a few minutes and is scriptable, so continuous integration pipelines can create one, deploy code, run tests, and delete it.
- Empty of your data and metadata. A new scratch org has none of your production org's customizations or records. You push your project's source into it.
- Created through a Dev Hub. A Dev Hub is a production org (or a trial or DE org) with the Dev Hub feature turned on. It tracks scratch orgs and enforces limits on how many you can create and how many can be active at once.
The Dev Hub requirement is the most common surprise for beginners. You cannot create a scratch org from a plain org that has not enabled Dev Hub. In Setup, search for Dev Hub and enable it. Enabling it cannot be undone in that org.
The definition file
This minimal file requests a Developer edition scratch org:
{
"orgName": "Tutorial Scratch Org",
"edition": "Developer"
}Real definition files usually add more keys. The ones you will meet most often are features (for example, enabling an optional capability), settings (preference values that match options in Setup), and release (to choose the preview or previous release). The file lives in your project, usually at config/project-scratch-def.json.
Creating a scratch org
Authorize your Dev Hub first, then create the scratch org from the definition file:
sf org login web --alias my-org
sf org list
sf org display --target-org my-orgThe first command opens a browser so you can log in and authorize the org with the CLI. The alias my-org is a short name for it. sf org list shows every org the CLI knows about. sf org display shows details for one org, such as its username and instance URL.
Now create the scratch org. The Dev Hub must be authorized, and it should be your default Dev Hub or be named with --target-dev-hub.
sf org create scratch --definition-file config/project-scratch-def.json --alias tutorial-scratch --duration-days 7This creates an org that expires in seven days. The CLI stores its credentials locally, so you can open it with sf org open --target-org tutorial-scratch and deploy your source to it.
When you finish, you can delete it early with sf org delete scratch --target-org tutorial-scratch. Deleting early also frees one of the active scratch org slots that your Dev Hub allows.
Comparing the two
| Property | Developer Edition org | Scratch org |
|---|---|---|
| Cost | Free | Counts against your Dev Hub's scratch org allocation |
| Lifetime | Persistent while in use | 1 to 30 days, then deleted |
| How it is created | Web sign-up | CLI or API from a definition file |
| Needs a Dev Hub | No | Yes |
| Reproducible from a file | No | Yes |
| Typical use | Learning, experiments, demos | Team development, CI testing, packaging work |
| Starting content | Standard setup, minimal data | Empty, shaped by the definition file |
Choosing between them
Use these questions to decide.
- Do you need the setup to be repeatable? If a team or a pipeline must start from the same state every time, use a scratch org.
- Do you want something that stays around? For long-term study or a personal project without source control, use a Developer Edition org.
- Do you need production's real configuration or data shape? Use a sandbox. Neither scratch nor DE orgs copy production.
- Do you have a Dev Hub? If not, and you want to start now, sign up for a DE org. You can enable Dev Hub in that DE org and then create scratch orgs from it.
That last point is useful. A DE org can serve as a Dev Hub, so one free sign-up gives you both a persistent org and the ability to create scratch orgs. Dev Hub allocations in a DE org are small, which is fine for learning.
Common errors and edge cases
- "Dev Hub not enabled" or no default Dev Hub. Enable Dev Hub in Setup, then authorize that org. If you have several, set a default with
sf config set target-dev-hub=my-orgor pass--target-dev-hub. - Scratch org limit reached. Dev Hubs cap the number of active scratch orgs and how many you can create per day. Delete orgs you no longer need.
- Missing features after creation. The definition file only enables what you list. If a feature or setting is absent, add it to
featuresorsettingsand create a new org. You cannot change the definition of an org that already exists. - Losing work at expiration. Setup changes made by clicking in a scratch org exist only in that org. Retrieve them into your project source before the org expires.
- Inactive DE org. An unused DE org can be deactivated. Log in from time to time, and keep anything important in source control.
Exercises
Exercise
Your team wants every developer and the CI pipeline to start each feature from an identical, empty org with the same features enabled. Which org type fits, and what file makes it repeatable?
Show answer
A scratch org. The definition file (for example, config/project-scratch-def.json) holds the edition, features, and settings, so any number of identical orgs can be created from it. A Dev Hub is required to create them.
Exercise
You run sf org create scratch and the CLI reports that no Dev Hub is available. List two ways to fix this.
Show answer
Enable Dev Hub in an org (Setup, search for Dev Hub) and authorize it with sf org login web, then either set it as the default with sf config set target-dev-hub=<alias> or pass --target-dev-hub <alias> to the command. A free Developer Edition org can be used as the Dev Hub.
Exercise
A colleague builds a feature by clicking in Setup in a scratch org with a 7-day expiration. On day 8 the work is gone. What should they have done?
Show answer
They should have retrieved the changed metadata into their project source and committed it before the org expired. Scratch orgs are deleted on expiration, and click-made changes exist only inside the org.