Scratch Org Snapshots was a long-awaited feature in the Salesforce ecosystem. After a private pilot phase, it entered public beta with the Spring '24 release, providing a new tool for managing Salesforce development environments.
Now with the Summer '24 release, Salesforce announced making snapshots generally available (GA).
This article is a complete guide for mastering Scratch Org Snapshots, which can potentially revolutionize your development workflow. I will explain Scratch Org Snapshots, how they can be used to quickly create dev environments, and highlight their unique benefits.
As a bonus, I will guide you through Hutte, a cutting-edge platform that streamlines org snapshot management, making it less complex and more efficient.
Do you want to speed up your Salesforce development process and minimize the time it takes to create and clone organizations? Dive in!
Scratch Org Snapshots capture the entire state of a scratch org at a given point in time. They serve as frozen snapshots of an org's configuration, metadata, and data. This provides Developers with a powerful tool for managing and replicating development environments.
Instead of manually configuring orgs or relying on cumbersome setup processes, Developers can simply clone a pre-configured snapshot to set up a new scratch org in seconds. This ensures consistency during the development, testing, and deployment phases.
Scratch Org Snapshots consist of a few key components:
This includes the org shape, editions, limits, and features of the Salesforce environment. By capturing configuration settings in a snapshot, Developers can ensure that new orgs are deployed with the same org shape as the original, maintaining consistency across different environments.
Scratch Org Snapshots store the Salesforce environment's metadata, including custom objects, fields, Flows, and Apex classes. This allows Developers to replicate the structure of their orgs accurately and ensure that any changes made in one environment can be easily transferred to others.
In addition to the configuration and metadata, Scratch Org Snapshots also capture the data that existed in the organization when the snapshot was created. This includes data records, relationships, and all sample data used for test purposes. With the data in the snapshot, Developers can create fully functional replicas of their orgs, enabling comprehensive testing and debugging.
We know that scratch orgs enable Developers to experiment freely without compromising production data as any changes made in it can be easily discarded or undone. Scratch Org Snapshots take it to another level. These snapshots help create scratch orgs with data easily without having to create one from scratch.
Salesforce allows you to create a Scratch Org Snapshot only from a scratch org or vice versa. Also, neither can replace Salesforce sandboxes for UAT (user acceptance testing). Here's why:
Before you get started with Scratch Org Snapshots for your Salesforce development projects, there are prerequisites that you need to meet:
Installing the Salesforce CLI (command line interface) on your computer is important. This tool provides a set of commands that lets you interact with Salesforce orgs and perform various development tasks.
Enable the Dev Hub feature in your Salesforce org. Dev Hub allows you to create and manage scratch orgs and enable other Salesforce DX features.
⚡️Author's note: This feature works in both Salesforce Classic and Lightning Experience interfaces.
Enable the Scratch Org Snapshots feature in your Dev Hub org. This allows you to capture snapshots of scratch org configurations for replication or version control purposes.
To activate Dev Hub and Scratch Org Snapshots (beta) in your Salesforce org, simply follow these steps:
Voila! You have completed the steps to start with Scratch Org Snapshots in Salesforce DX. Using CLI commands, you're now equipped to create, manage, and replicate scratch orgs with snapshots.
If you want non-admin users to be able to create and access snapshots in Salesforce, you need to assign them the proper license and permission set. While Dev Hub administrators can do this by default, it is important to ensure that other users have the necessary permissions for smooth collaboration.
Here comes the exciting part! The Scratch Org Snapshot functionality allows you to freeze your org's configuration, data, and metadata so that you can easily recreate it later.
After you have authorized Dev Hub, you need to create a scratch org to take a snapshot of. To create a scratch org, run the following command in your terminal:
Sf org create snapshot --name <your_snapshot_name> --source-org <your_scratch_org_alias> --target-dev-hub <your_dev_hub_alias> --description "<optional_description>”
Replace the following code with your details:
For example:
sf org create snapshot --name VCsnapshot1 --source-org ScratchOrgforVC --target-dev-hub rsales
While creating the snapshot, wait for the command to complete and check the terminal for progress messages. It enables faster and more efficient development by:
Here is a step-by-step guide on how to create a scratch org based on a Scratch Org Snapshot in Salesforce DX:
You must have Salesforce DX installed and configured (for the development experience) in your software development environment, such as VS Code.
I am sure you already have an instance of a scratch org created. If not, follow the instructions for creating a snapshot first.
Launch a terminal or CLI command in the Salesforce DX project directory:
sf org create scratch --definition-file Config/snapshot-scratch-def.json --alias your-scratch-org-alias --target-dev-hub your-dev-hub-alias --wait 10
Generally, it takes Salesforce a little longer to execute the request. Hence, increase the "--wait" value to ensure the command doesn't die out before execution.
Use the command to create a snapshot of your scratch org. Creating snapshots using CLI commands for Salesforce scratch orgs provides a convenient way to capture the org's state at a specific point in time.
The list command is used to see all the snapshots you've created and learn about each one. It helps you keep track of your org's status and see how your development and testing work is going.
This command lets you delete a Scratch Org Snapshot. When you're handling Salesforce Scratch Orgs, deleting snapshots is essential to keep everything tidy and running smoothly.
You can use this command to get details of the snapshots that have already been created.
You can use the "--help" and "-h" flags in the command window to get different levels of help – detailed or short. For example, "sf org create snapshot -help."
Developers can quickly create orgs from a snapshot, making testing and development easier without setting up new orgs or creating sandboxes for testing. This avoids doing the same setup again and again, which saves time and lowers the chance of mistakes.
Moreover, Developers can smoothly switch between different org setups, allowing them to work on various features or fix bugs simultaneously without redoing configurations.
When Developers use a snapshot to start new orgs, everyone on the team gets the same starting point. This means no more manual setup, which reduces mistakes and keeps things consistent. With snapshots, sharing the same setup with team members is easy. Instead of writing down and passing around all the setup details, Developers can simply share the snapshot.
If issues arise during deployment, Scratch Org Snapshots enable quick rollback of changes. Developers can use snapshots to restore the org to a previous state, which creates a safety net and builds confidence during production deployments.
In short, Scratch Org Snapshots' main advantage is that you can create a perfect dev environment with the right metadata, data, and org shape. Moreover, it also helps you quickly create replicas of scratch orgs for other Developers and QA.
If you're familiar with Hutte, you'll appreciate its unique features. Hutte's strength lies in its commitment to early adoption and continuous improvement, ensuring a superior user experience. Its user-friendly interface makes it particularly appealing to those who prefer less command-line interaction.
Using Hutte's UI, you can create and manage your org snapshots from any scratch org and effortlessly apply them when creating new scratch orgs. Alternatively, you can build a personalized Scratch Org Pool directly from your existing snapshots.
But before you start, activate snapshots on your Dev Hub linked to Hutte.