What are scratch orgs?

Scratch orgs are like normal orgs, except that they are short-lived (by default, they expire after 7 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 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 now create, compare and deploy both 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 have to first enable and connect a Dev Hub org, which acts as a 'master org' that controls all of the scratch orgs. From that Dev Hub you can create and delete scratch orgs, which will all 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 My connections.
  • Click 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

  • This will open a window that enables you to create a scratch org from a definition file, or determine the settings for your scratch org using a form.
  • Click 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 Hubs page).
  • 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.
Did this answer your question?