What are scratch orgs?
Scratch orgs are like normal orgs, except that they are short-lived (by default, they expire after seven days, although you can set the duration to between 1 and 30 days) and can be created very quickly. Scratch orgs are useful for running your Apex code and tests in an environment that’s realistic and clean, and for testing that your deployments will work using an org that isn’t critical and can be forgotten about.
Gearset’s SFDX scratch org support
Within Gearset, anyone can create, compare, and deploy metadata and data to or from SFDX scratch orgs in a matter of clicks. You can even log into the orgs with a click for easy UI-based modifications. It’s all the power of DX, without the command line.
Enabling and connecting a Dev Hub
To create scratch orgs, you must first enable and connect a Dev Hub org, which acts as a ‘master org’ that controls all of the scratch orgs. Then, from that Dev Hub, you can create and delete scratch orgs — all of which will be linked to that Dev Hub until they expire.
You first need to enable Dev Hub for a Salesforce org, using the Salesforce user interface. (For information on how to do this, take a look at their support guide.)
If you haven’t yet linked this org to Gearset, navigate to the Salesforce orgs page, under
ADD NEW ORGANIZATION…and add your Dev Hub org as a normal org connection.
Your Dev Hub should now appear in your list of current orgs.
It is possible to add multiple Dev Hubs.
Setting up scratch orgs
Once you have connected one or more Dev Hubs, you are ready to start creating scratch orgs.
Method 1: from the ‘Salesforce orgs and Dev Hubs’ page
On the Salesforce orgs and Dev Hubs page of the app, click
Create scratch orgnext to your chosen Dev Hub.
This will open a window that enables you to either create a scratch org from a definition file or to specify the settings for your scratch org using a form:
We also have a feature in beta to use an Org shape to create a scratch org. (You would need to enable your org shape and create an org shape using SFDX.)
Create scratch org. The creation process usually takes under 30 seconds, but can take longer depending on the speed of Salesforce.
Once the scratch org has been created, you will see it referenced in the org list on the Salesforce orgs and Dev Hubs page.
Method 2: from the ‘Compare metadata’ page
Head to the Compare and deploy page under
Metadata deployments, and click on
SFDX scratch org(as either source or target).
You will be able to see the Dev Hub(s) you have connected and any scratch orgs you have already created. To create a new scratch org from here, select the Dev Hub you want to create a scratch org for from the top drop-down menu, and click on
+ Create new scratch org.
This opens a window with basic configuration (shown below) to enable you to define a scratch org really quickly. If you want to upload a definition file or fine-tune any other settings, click on the
Additional creation options...to open the main scratch org creation form (that we saw earlier when creating a scratch org from the
Salesforce orgs and Dev Hubspage).
Once you have created a scratch org, on the Compare and deploy page (under
Metadata deployments) you can select your scratch org as a source or target of a comparison. If you have scratch orgs corresponding to multiple Dev Hubs, ensure you select the relevant Dev Hub via the first drop-down menu to see the linked scratch orgs in the second drop-down menu for you to select from.
On this page, you’ll also see a link to log into your selected scratch org - no password necessary.
You are now all set to follow the usual Gearset metadata workflow and start configuring metadata comparisons and deployments to (or from) your scratch orgs! For general guidance, see our quick start guides.
Method 3: from the ‘Deploy data’ page
You can also create scratch orgs on the Configure and deploy page under
Data deployments. The process of creating a scratch org and selecting it as either your source or target is exactly the same as the workflow described above for metadata deployments.
If you need help with configuring your data deployment, take a look at our walkthrough guide.