The Developer Hub (Dev Hub) is one of the crucial features for App developers. I am using scratch org for the last few weeks and sharing my experience here. Let’s get started
What is Scratch Orgs?
The scratch org is based on the concept of source-driven development. Disposable deployment of Salesforce code and metadata, made for developers and automation makes it easier to use.
Scratch org drives developer productivity and collaboration during the development process and facilitates automated testing and continuous integration.
Imagine a situation where you are working on an enterprise project with multiple business units and different SI partners. How about creating a package of your business unit metadata and spinning up a scratch org for a user story/feature development. This strategy will help you to keep your development separate from other SI.
After creating the scratch org definition file, you can easily spin up a scratch org from the tool that you use daily, yes you got it right, i.e. Visual Studio Code and open it directly from the command line.
Before you make a scratch org:
Set up your Salesforce DX project
Authorize the Dev Hub org
Create the scratch org definition file
Advantages of Scratch org over the sandbox
The big difference between the two is that
Flexibility to create scratch org by modifying the definition file, which is not possible with sandbox. For example, only copying metadata for one business unit.
They are disposable: You can delete them when you are done.
What is the purpose of DevHub?
The Developer Hub (Dev Hub) lets you create and manage scratch orgs from the command line, view information about your scratch orgs, and link namespace orgs.
To work with scratch orgs, you must first enable the Developer Hub (DevHub) in your production or business org. Then you can use the Salesforce command-line interface (CLI) to create scratch orgs.
How to enable Dev Hub?
To enable Dev Hub in an org:
From Setup, enter Dev Hub in the Quick Find box and select Dev Hub.
To enable Dev Hub, click Enable (once Dev Hub is enabled, you can’t disable it).
Scratch Org Expiration Policy
A scratch org is temporary and deleted along with the associated ActiveScratchOrgs records from the Dev Hub after expiration.
Scratch orgs have a maximum 30 days lifespan. You can select a duration from 1 to 30 days at the creation time, with the default set at seven days.
Once the scratch org has expired, you can’t restore it.
Scratch org Allocation
Dev Hub org edition defines your scratch org allocations to ensure optimal performance. These allocations specify how many scratch org can be creat daily and how many can be active at a given point.
Storage limits of Scratch orgs are:
200 MB for data
50 MB for files
Connect Visual Studio Code to the org in which you want to create a scratch org.
Use this link to set up and connect your org with Visual Studio Code and install Salesforce CLI from here.
Create a Scratch org from VS Code
Press Command + Shift + P on Mac or Ctrl + Shift + P on Windows to make the command palette appear.
Make sure the new prompt starts with >
Search for SFDX: Create Project and press Enter.
Select Standard Standard Project template (default) and press Enter.
Enter your Project name and press Enter.
Now, search for SFDX: Authorize a Dev Hub and press Enter. It will prompt the browser to verify credentials.
Search for SFDX: Create a Default Scratch Org., select and press Enter.
Select the default Scratch definition file, select and press Enter.
Enter your Scratch Org name and press Enter.
Enter the number of days to set the expiration for your Scratch org from 1-30.
Watch the video for steps to follow in detail:
Read my next blog post for the below topics in detail:
Setup the user account in Scratch org
Pull source code to the Scratch org
Push source code to the Scratch org
Points to remember:
You can’t enable Dev Hub in a Developer Edition org with a registered namespace.
You can’t enable Dev Hub in a sandbox.
Once you enable Dev Hub, you can’t disable it.
Deleting a scratch org doesn’t terminate your scratch org subscription. You can create a new scratch org if your subscription is still active. Creating a new scratch org counts against your daily and active scratch org limits.
Delete any unneeded or malfunctioning scratch orgs in the Dev Hub org or via the command line so that they don’t count against your active scratch org allocations.
You are done!!!
I would love to hear about your experience working with Dev Hub and scratch org. How do you use it?