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 a real environment and testing that your deployments will work on 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 to SFDX scratch orgs in a matter of clicks. Simply choose the org type, click create, and you're ready to start building and testing your code in a clean environment. 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 an org to act as your Dev Hub, and to do that you must 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.
  • ADD NEW ORGANIZATION… and add your your Dev Hub org as a normal org connection. Your Dev Hub should now appear in your list of current orgs.
  • Select the SCRATCH ORGS AND DEV HUBS section (at the top of the page), and then click SELECT SFDX DEV HUB and choose your Dev Hub org from the list. Click Set as dev hub.
  • Your connected Dev Hub will now be listed on the Scratch org and dev hubs page.

Setting up scratch orgs

Once you have connected your Dev Hub, you are ready to start creating scratch orgs.

  • Head to the Compare and deploy page under Metadata deployments and click on SFDX scratch org. You will be able to see your connected Dev Hub, which you can create scratch orgs from.
  • Click +Create new scratch org, give it a friendly name, and choose what type of org to create and how long you want it to be active for.  Click Create scratch org. (This usually takes under 30 seconds, but can take longer depending on the speed of Salesforce.)
  • Optional: if you want to configure additional options, click on the Additional creation options... to upload a definition file or fine tune any other settings, including specifying unlocked packages you want installed when the org is created.
  • Once you have created a scratch org, you’ll see a link to log into your scratch org - no password necessary.
  • You are now all set to follow the usual Gearset workflow and start configuring comparison and deployments to your scratch orgs! 

Deploying data to SFDX scratch orgs

Within Gearset you can also create, compare and deploy your data to SFDX scratch orgs. 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. To deploy data to a scratch org, simply head to the Configure and deploy page, under Data deployments in the left-hand side menu.

If you need help on configuring your data deployment, take a look at our walkthrough guide.

Did this answer your question?