Sub topic 8
Choosing the right org for the task
Earlier chapters covered each non-production org type on its own. This chapter shows how to choose among them for a specific piece of work. It assumes you can already create a sandbox and a scratch org, you know what a Dev Hub is, and you are comfortable with metadata deployments and Git branches.
Why the choice matters
Picking the wrong org costs time in predictable ways:
- A scratch org used for a data-heavy performance test has no realistic data, so the results mean nothing.
- A Full sandbox used for daily feature work is slow to refresh and expensive, and it may hold production data that developers should not see.
- A Developer sandbox used for integration testing runs out of storage before the test finishes.
Each type is a trade-off between four properties: what data it holds, how closely its configuration matches production, how long it lives, and how quickly you can get a fresh one. Start from the task and work back to those properties.
The four properties to compare
| Org type | Starting data | Configuration source | Lifespan | Fresh copy |
|---|---|---|---|---|
| Scratch org | None, or data you load | Definition file plus source from Git | 1 to 30 days, default 7 | Minutes, on demand |
| Developer sandbox | None (metadata only) | Copy of production | Until deleted | Refresh every 1 day |
| Developer Pro sandbox | None (metadata only) | Copy of production | Until deleted | Refresh every 1 day |
| Partial Copy sandbox | Sample of production data, chosen by a template | Copy of production | Until deleted | Refresh every 5 days |
| Full sandbox | All production data | Copy of production | Until deleted | Refresh every 29 days |
Storage differs by type. A Developer sandbox holds 200 MB of data, a Developer Pro sandbox holds 1 GB, a Partial Copy sandbox holds up to 5 GB, and a Full sandbox matches production. Limits and intervals can change between releases, so confirm current numbers in the Salesforce documentation before you rely on them.
Two ideas in the table drive most decisions:
- Configuration source. A sandbox inherits production's configuration, including drift, unfinished changes, and unmanaged customizations. A scratch org inherits only what you declare, so it reflects your source repository and nothing else.
- Data. Only Partial Copy and Full sandboxes carry production records. Everything else needs seed data that you create.
Walking through the decision
Ask these questions in order. The first one that gives a firm answer usually settles the choice.
- Does the task need production-scale or production-shaped data? Performance tests, load tests, data migration rehearsals, and some reporting work do. Choose a Full sandbox. If realistic shape matters more than volume, a Partial Copy sandbox with a template may be enough.
- Does the task need production's exact current configuration? Examples are staging a release, training users, and reproducing a bug that depends on an odd setting. Choose a sandbox, because it is a copy of production as it is today.
- Is the work source-driven, with metadata in Git and a team that can rebuild an org from it? Examples are feature development, package development, and automated test runs. Choose a scratch org.
- Is the work admin-led, such as building a flow or layout in the browser with no repository? Choose a Developer sandbox. It is simple, it persists, and it needs no Dev Hub.
- Does the work need more than 200 MB of test data or heavier testing capacity? Move up to Developer Pro. It is the same kind of org with more storage.
The diagram combines these questions into one flow.
Common tasks and the usual answer
The framework gives these defaults. Treat them as starting points and adjust for your team.
| Task | Usual choice | Reason |
|---|---|---|
| Build a feature on a branch | Scratch org | Isolated, disposable, and rebuilt from source |
| Run unit tests on each pull request | Scratch org | Fresh, identical state for every run |
| Develop a managed or unlocked package | Scratch org | Package development expects a clean org |
| Admin builds declarative changes | Developer sandbox | Persists, mirrors production, needs no repository |
| Integration testing with a larger data set | Developer Pro sandbox | More storage than Developer |
| User acceptance testing with realistic records | Partial Copy sandbox | Sample production data with production configuration |
| Performance and load testing | Full sandbox | Full data volume |
| Release rehearsal and staging | Full sandbox | Same data and configuration as production |
| Reproduce a production-only bug | Sandbox, usually Partial Copy or Full | The bug depends on production data or configuration |
| Prototype a Salesforce feature or trial a new setting | Scratch org | Cheap and throwaway |
Fidelity versus freshness
Teams often mix up two kinds of "same as production."
A sandbox is faithful to production at the moment of its last refresh. After that it drifts. Anyone who changes production directly, or deploys there without updating the sandbox, widens the gap. A sandbox that has not been refreshed for months can pass tests that production then fails.
A scratch org is faithful to your source. If the repository is incomplete, because someone made a change in production and never retrieved it, the scratch org is missing that change. Tests that pass in the scratch org can fail in production for the same reason.
Both failures share a cause: source of truth and reality disagree. A sandbox gives you reality with no record of how it got there. A scratch org gives you the record with no guarantee it matches reality. For this reason many teams use both: scratch orgs for building and testing, and a Partial Copy or Full sandbox as a staging step that checks the result against production's real state.
Checking capacity before you commit to scratch orgs
Scratch org plans depend on the Dev Hub's allocation. Each Dev Hub has a cap on active scratch orgs and a separate cap on scratch orgs created per day. Check both before you design a CI process that creates one per pull request.
sf limits api display --target-org devhubLook for ActiveScratchOrgs and DailyScratchOrgs in the output. Each has a maximum and a remaining count. A team with 30 developers and a CI job that creates a scratch org for every push can reach the daily cap before lunch. When that happens, options include deleting orgs promptly, creating one per pull request instead of one per push, or asking Salesforce about a larger allocation.
Sandboxes have their own limits. Each edition includes a fixed number of each sandbox type, so a team may be unable to give every developer a Developer sandbox. That limit is a real reason to choose scratch orgs.
Data is part of the decision
Do not choose a sandbox only because "it has data." Ask what kind of data the task needs.
- No data. Scratch orgs and Developer or Developer Pro sandboxes work. Unit tests should create their own records anyway.
- Small, known data. Use seed scripts or data files that load into any org. This works the same in a scratch org and in a Developer sandbox.
- Representative data. Use a Partial Copy sandbox with a sandbox template that selects the objects to copy.
- Everything. Use a Full sandbox.
Anything that copies production records also copies sensitive values. Before developers get access, decide how you will mask or scrub personal data. A scratch org avoids the problem because it never holds real customer data. If you choose a Partial Copy or Full sandbox for data fidelity, plan the masking at the same time and run it automatically after each refresh with a SandboxPostCopy class.
Example: choosing for a real project
Suppose a team is building a quoting feature. The work has four phases, and each phase wants a different org.
- Build. Each developer works on a branch in a scratch org created from
config/project-scratch-def.json. They push source, test locally, and delete the org when the branch merges. - Automated checks. The CI job creates a scratch org per pull request, deploys source, and runs Apex tests. It deletes the org when the run finishes.
- User acceptance. The merged work goes to a Partial Copy sandbox. Business users test with a sample of real accounts and opportunities.
- Release rehearsal. Before the release, the team deploys to a Full sandbox and checks timing, data behavior, and the deployment steps.
The same project with a different shape gives a different answer. If the same feature were built by one admin with no repository, the first two phases would collapse into a single Developer sandbox, and the later phases would stay the same.
A sandbox definition for the acceptance phase shows how little changes between types. Only the license type differs from the Developer sandbox file in the earlier chapter.
{
"sandboxName": "uat1",
"licenseType": "PARTIAL"
}Create it the same way as any sandbox:
sf org create sandbox --definition-file config/uat-sandbox-def.json --alias uat1 --target-org prodA Partial Copy sandbox normally also references a sandbox template, which controls the data sample. Create the template in Setup first, then add its ID to the definition file.
Mistakes in the decision itself
- Using one org type for everything. A team with only Full sandboxes pays in refresh time and exposed data. A team with only scratch orgs has no realistic staging step.
- Choosing by habit. "We have always used Developer Pro" is not a reason. Check whether the task needs the extra storage.
- Ignoring refresh intervals. After you refresh a Full sandbox you cannot refresh it again for 29 days. If you need a clean copy sooner, you must wait or use another org type.
- Treating a scratch org as long-lived. It expires. Anything you want to keep must be in source control or exported.
- Forgetting that sandboxes inherit drift. A shared sandbox can carry changes nobody remembers making.
Summary of the working model
Choose in this order: data needs first, then configuration needs, then whether the work is source-driven, then storage and capacity. Use scratch orgs for building and testing code that lives in Git. Use sandboxes when you need production's actual state or its data. Combine them in a pipeline so that disposable orgs catch errors early and a production-like sandbox confirms the result.
Exercise
A team of eight developers keeps all metadata in Git and wants isolated environments for feature work. They also need to rehearse a release against production-volume data and measure how long a batch job takes. Which org types should they choose for each need, and why?
Show answer
Use scratch orgs for feature work. They are created from the definition file and the Git source, they are isolated per developer, and they can be discarded after the branch merges. Use a Full sandbox for the release rehearsal and the batch job timing, because only a Full sandbox holds production-volume data and matches production's configuration. A Partial Copy sandbox would hold only a sample, so its timing results would not predict production behavior.
Exercise
A scratch org passes all Apex tests on a pull request, but the same code fails in production. Name two reasons the choice of org could explain this, and one change to the pipeline that reduces the risk.
Show answer
First, the repository may be missing a change that was made directly in production, so the scratch org differs from production. Second, the scratch org has no realistic data, so a data-dependent failure never appears. Adding a Partial Copy or Full sandbox as a staging step before production catches both problems, because the sandbox reflects production's real configuration and data.