Sub topic 3
Sandbox Types and Sandbox Templates
Assume you know Salesforce objects, relationships, CLI basics, and Apex syntax. A sandbox is a copy of a Salesforce production org used for development, testing, or training. A sandbox template controls which production data a sandbox receives.
Sandbox Types and Templates
| Sandbox type | Typical contents | Common use |
|---|---|---|
| Developer | Metadata and a small data limit | Daily development |
| Developer Pro | Metadata and more test data | Larger development tasks |
| Partial Copy | Selected production data from a template | Integration and user acceptance testing |
| Full | All production data | Final performance and release testing |
Developer and Developer Pro sandboxes usually need seed scripts because they do not copy production records. A Partial Copy template selects objects and fields for copied data. A Full sandbox copies production data, but you may still need post-refresh setup.
Preparing a Refreshed Sandbox
A class that implements SandboxPostCopy can run automatically after a sandbox is created or refreshed. Select the class in the sandbox configuration.
global class PrepareSandbox implements SandboxPostCopy {
global void runApexClass(SandboxContext context) {
insert new Account(
Name = 'Sandbox Test Account',
Industry = 'Technology'
);
}
}Keep this class small. Use it for safe configuration and baseline records, not for importing a large dataset.
Protecting Data and Repeating Loads
Do not copy unmasked customer data, credentials, tokens, or personal information into development environments. Prefer synthetic data. If production data is required, use Salesforce data masking or another approved masking process.
Make seed scripts idempotent, meaning repeated runs produce the same intended state. Store a stable external ID such as Seed_Key__c, then upsert records by that field. This prevents duplicate records during local setup or CI runs.
Synthetic Data, CI, and Troubleshooting
Synthetic data generators such as Snowfakery can create realistic records without exposing production values. A setup script can create or select an org, deploy metadata, load seed data, and run validation. Run the same script locally and in CI so both environments use the same process.
Common failures have predictable causes:
- Missing required fields: add the field or provide a valid default.
- Unresolved references: import parent records first and check reference IDs.
- Validation-rule failures: use values allowed in the target environment or temporarily adjust approved test configuration.
- Duplicate records: use external IDs and upsert instead of insert.
> callout warning > Review post-copy and CI scripts before running them against a production org. Target the org explicitly.
Exercise
Which approach is best for a Developer sandbox that must be reset and populated repeatedly?
Show answer
Use a repeatable script with synthetic data and external-ID upserts.