A Salesforce scratch org is a temporary Salesforce instance, typically used for a specific development. As part of the Salesforce DX collection of tools, these are aimed towards developers or architects with experience in Salesforce CLI and Visual Studio Code.
In this post, I’ll attempt to demystify scratch orgs by covering the differences between scratch orgs and sandboxes (and when to use each). I’ll also explore the developer hub, scratch org limits, and how to create scratch orgs and org shapes.
What Is a Scratch Org in Salesforce?
A scratch org is a “source-driven and disposable deployment of Salesforce code and metadata”. As the name suggests, scratch orgs are empty by default, allowing you to ‘start from scratch’. As such, they are ideal for testing out new features and projects – I like to think of these as a ‘scratch pad’ for Salesforce.
Scratch Org vs. Sandbox – What Are the Differences?
Let’s have a quick recap of Salesforce Sandboxes – these are test environments linked to your production environment. There are four different types:
- Developer Pro
- Partial Copy
Unlike sandboxes, scratch orgs do not have a refresh interval as they are disposable.
The main difference between scratch orgs and sandboxes is that scratch orgs take the metadata from a configurable file, whereas sandboxes copy metadata from your Salesforce environment.
By default, a scratch org has no records on creation, but certain sandboxes (such as Partial or Full) will have records from your production environment.
Sandboxes are also tied to your Salesforce edition, whereas scratch orgs can run on a specific edition based on your configuration file.
Scratch Org vs. Sandbox – When to Use Each?
Scratch orgs are typically used at the beginning of development, as they can be spun up (and deleted) quickly.
In the world of DevOps, they can be linked to your Source Control System to test new changes without the risk of breaking your deployment pipeline.
Each developer could have their own scratch org to increase productivity. This also means that developers can avoid bumping into each other when creating rapid POCs.
When developing and testing new apps, AppExchange partners often use scratch orgs to ensure features work across different editions.
For use cases later in the development cycle, you should use a sandbox instead. Sandboxes have greater storage and are tied to your Salesforce org. Examples of when to use sandboxes over scratch orgs include:
- Integration testing
- User training
- User acceptance testing
Meet the Developer Hub
When you create a scratch org, you define the edition between Developer, Enterprise, Group, or Professional.
A Salesforce scratch org is ‘born’ from a Developer Hub (Dev Hub) org. A Dev Hub can either be your production org or a separate developer org. This is the central place for managing your scratch orgs.
Scratch Org Limits
The limits for scratch orgs are split into two parts based on your Salesforce edition:
- How many you can create daily.
- How many can be active at one time.
It’s important to note that the limits for partner scratch orgs are different and can be found here.
A scratch org can only hold up to 200MB of records and 50MB of files.
How to Create a Scratch Org in Salesforce
I have broken the creation process into three simple steps for you:
- Set up Salesforce Developer Experience (DX) tools.
- Create a scratch org definition file – a cookbook of features and settings you want the scratch org to use.
- Run a command to kick off the process.
What Is an Org Shape (Beta)?
In Winter ‘21, Salesforce released the org shape function to help capture what you need – this can be used to create the scratch org definition file.
An org shape captures key settings such as:
- Features (e.g. person Accounts)
- Settings (e.g. for Email to Case)
- Edition (e.g. Enterprise)
It’s useful to know that as this is in beta, it doesn’t yet benefit from Salesforce support. You can only have one org shape active and a shape is tied to a specific release e.g. Summer ‘22.
Like scratch orgs, you’ll run certain commands in Visual Studio Code using Salesforce CLI to manage shapes.
When it comes to creating specific environments for development projects, a Salesforce scratch org is a great tool for architects and developers alike.
Scratch orgs can be daunting at first, so be sure to run through the tools on Trailhead to help get you started. And when weighing up whether to use a sandbox or a scratch org, think about where you are in the project/program cycle, as this position should drive your decision.
Fingers crossed the org shape feature makes it out of beta soon. With new functionality entering the world of Salesforce DevOps (e.g. Salesforce DevOps Center), I expect to hear about more exciting developments soon!