Sub topic 10
Sandbox types and sandbox templates
This chapter assumes you can run sf commands against a production org, you know what a sandbox is, and you have read the previous chapter on how scratch orgs and sandboxes differ at creation. The sandbox types and the template feature below decide how much data a new sandbox starts with.
What each sandbox type copies
The sandbox type, also called the license type, sets two things. It sets how much data the sandbox can hold, and it sets whether production records are copied at all.
| Type | Data copied from production | Data storage limit | Minimum refresh interval |
|---|---|---|---|
| Developer | None (metadata only) | 200 MB | 1 day |
| Developer Pro | None (metadata only) | 1 GB | 1 day |
| Partial Copy | Sample, chosen by a template | 5 GB | 5 days |
| Full | All records | Same as production | 29 days |
Limits change between releases, so check the Salesforce help for your edition before you plan around them. The pattern is stable: Developer and Developer Pro sandboxes start empty, like scratch orgs. Only Partial Copy and Full sandboxes carry production data.
Where templates fit
A sandbox template is a saved list of objects. When you create a Partial Copy or Full sandbox with a template, Salesforce copies the records of only those objects. Templates are not available for Developer or Developer Pro sandboxes.
Partial Copy sandboxes copy a limited sample, up to 10,000 records per selected object. The sample is not one you pick record by record. Related records may be missing, so test the result before you rely on it.
Creating a sandbox with a template
You create templates in Setup, in the production org, under Sandbox Templates. Choose the objects to include, then save. Copy the template ID, which starts with 0EM.
Reference the template in a sandbox definition file:
{
"sandboxName": "QA1",
"licenseType": "Partial",
"templateId": "0EM000000000001AAA",
"description": "Partial sandbox for QA with Account and Contact data",
"autoActivate": true
}Replace the templateId value with your own template ID. Then create the sandbox from the production org:
sf org create sandbox \
--definition-file config/sandbox-def.json \
--alias qa1 \
--target-org my-production-org \
--wait 60The command polls until the sandbox is ready or the wait time runs out. Sandbox creation can take hours for large orgs. If the wait expires, the sandbox keeps building and you can resume with sf org resume sandbox.
Common errors
- Choosing a template for a Developer sandbox. The template is ignored or rejected, because those types copy no records.
- Expecting related records to arrive. A template that includes Contact but not Account can leave Contacts with empty lookups. Include the parent objects.
- Treating a template as a masking tool. A template limits which objects are copied. It does not hide field values. A copied Contact still carries its real email address.
A template gives you a sample, not a guarantee. The usual approach is to pair a template with a post-copy Apex class that adds the specific records your tests expect. That class is the topic of the next chapter.
Exercise
Your team needs a sandbox that starts with Account and Contact records from production, but only a small sample, and refreshes every week. Which sandbox type and which feature do you use?
Show answer
A Partial Copy sandbox with a sandbox template that includes Account and Contact. Developer and Developer Pro sandboxes copy no records and do not support templates. A Full sandbox copies everything and has a 29-day minimum refresh interval, so it does not fit a weekly refresh. Partial Copy's 5-day minimum does.