Salesforce DevOps, Scratch Orgs & Environment Strategy
A scratch org is not a miniature production org
A clean build passed; the production dependency did not exist
A feature branch deploys into a new scratch org, Apex tests pass and the pull request is approved. In production, the release fails because a managed package version differs, an integration identity lacks a permission, a record type assumed by the seed script has another developer name and years of data expose a query path the clean org never exercised. The scratch org did its job. The team asked it to prove something it was not designed to prove.
The JSBC Labs position is that a scratch org is a reproducible development environment—not a miniature production org. Salesforce defines scratch orgs as empty, temporary environments created from source, with a lifespan chosen between one and 30 days. Their value is disposability: they reveal whether source, dependencies and setup automation can construct a working solution. Production fidelity is a separate requirement that belongs to a deliberate environment and test strategy.
Use the empty org as an architectural test
An empty environment is useful precisely because it contains no accumulated rescue work. If a team cannot create the org, deploy the metadata, install dependencies, assign access and seed the minimum data from an automated process, the repository is not yet a complete description of the solution. Manual setup instructions, remembered clicks and configuration stored only in a long-lived sandbox are hidden production dependencies.
Treat scratch-org creation as an executable build contract. Version the definition file, package directories, dependency versions, permission assignments, seed-data scripts and post-deployment steps. Fail the build when a required artefact is missing. Salesforce recommends keeping the scratch definition in version control; that file declares edition, features, settings and selected object settings. The JSBC Labs analysis is that every remaining manual step should be classified as a temporary gap, a deliberate secret-handling boundary or an unsupported platform constraint—not normal delivery practice.
Org shape is a baseline—not a clone
Org Shape can capture a source org's edition, features, limits and supported Metadata API settings, reducing the work required to describe a complicated enterprise baseline. Salesforce is explicit that an org shape does not include all metadata or data entries, and it should be recreated after the source org moves to a new Salesforce release. A successful shape-based build therefore proves compatibility with a captured baseline, not equivalence with the live estate.
Keep the shape refresh procedure owned and observable. Record the source org, Salesforce release, capture date and build pipelines that consume it. Add missing features and settings explicitly in the definition rather than relying on tribal knowledge. Validate the produced org with automated assertions: expected licences, installed packages, key settings, sharing defaults and API versions. The shape accelerates environment construction; the assertions tell you whether the constructed environment is fit for this change.
Snapshots accelerate dependencies—but also freeze them
Scratch Org Snapshots can include installed packages, features, limits, licences, metadata and data, making them valuable when a clean build spends most of its time recreating stable prerequisites. Salesforce also describes snapshots as static point-in-time copies: updating one means replacing it. It states that snapshots do not replace source-driven development, version control or sandboxes for user acceptance testing.
Use a snapshot for expensive, stable dependencies—not as an opaque golden org. Keep application source and test data outside the snapshot where practical, publish a manifest of what the snapshot contains and rebuild it when a dependency or release baseline changes. Connected apps, external credentials and named credentials are not copied into snapshots, so credential configuration still needs a secure environment-specific process. Faster creation is useful only when teams can explain exactly what was accelerated.
Seed scenarios—not a theatre set
A handful of attractive demo records can make a feature look complete while leaving its failure modes untouched. Scratch data should express contracts: the account with no owner, the user with restricted field access, the parent with many children, the duplicate external identifier, the expired configuration and the record that takes the negative branch. Generate deterministic data with durable business keys so tests can locate it without environment-specific IDs.
Keep data volume proportional to the question. Small, isolated datasets are ideal for unit and component tests; they make failures fast and diagnosable. They cannot expose production cardinality, skew, locking, sharing recalculation or batch duration. Do not inflate every scratch org into a slow pseudo-production copy. Route scale questions to a representative sandbox and make synthetic or masked data part of that environment's governed test plan.
Mock boundaries deliberately—then test the real ones elsewhere
Scratch orgs often cannot or should not connect to production services. Use mocks, stubs and test endpoints to prove application decisions, error mapping and retry behaviour without exposing customer data or credentials. Externalise endpoints and feature switches through deployable configuration, and inject secrets only through the environment's approved secret mechanism. A test double should have a named contract and owned fixtures, not simply return success for every request.
Then maintain a separate integration stage that exercises the real authentication flow, schemas, network controls and provider behaviour against non-production endpoints. Salesforce Well-Architected describes integration sandboxes as shared environments for multi-component workflows and staging sandboxes as higher-fidelity release environments. The evidence should identify which boundary was mocked in the scratch org and where the real contract was verified. Otherwise a green pipeline silently promotes an untested assumption.
Choose environments by evidence required
Use scratch orgs for isolated feature work, package assembly, static analysis, focused automated tests and pull-request validation. Use a shared integration sandbox when features must interact with common automation, managed packages and test services. Use UAT for business acceptance with representative personas and workflows. Use a staging or Full Copy environment when deployment rehearsal, data migration, production-scale performance or complex sharing behaviour requires high fidelity.
This is not a rigid march through every environment for every change. A label correction should not carry the same evidence burden as a new integration or ownership model. Define risk-based promotion rules: which changes require a package dependency test, representative data, security persona testing, external integration proof, volume testing or a rollback rehearsal. Environment cost is real, but skipping the evidence does not remove risk; it transfers discovery to production.
Make reproducibility the gate—not the slogan
Measure the scratch-org path as a product. Track creation success, time to usable state, manual interventions, undeployable metadata, flaky tests and drift between the declared baseline and downstream environments. Delete and recreate environments routinely; a build that works only in yesterday's org is evidence of hidden state. Keep creation logs and test results with the commit so reviewers can connect approval to a specific source version and environment definition.
The strongest DevOps model does not choose scratch orgs or sandboxes as competing philosophies. It uses each to answer a different question. A scratch org asks whether the solution can be reconstructed from controlled source. Integration and staging environments ask whether that solution behaves correctly inside the wider estate and release process. When those questions stay separate, teams gain both fast feedback and honest production confidence.
Official references
- Salesforce Developers — Move Metadata Changes to and from a Scratch Org
- Salesforce Developers — Salesforce Development Models
- Salesforce Developers — Build Your Own Scratch Org Definition File
- Salesforce Developers — Scratch Org Snapshots
- Salesforce Developers — Create and Manage Org Shapes
- Salesforce Architects — Operational Excellence
- Salesforce Architects — Operational Excellence: DevOps Patterns