What are scratch orgs?

Scratch orgs are like normal orgs, except that they expire after 7 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 a Dev Hub inside Salesforce (for information on how to do this take a look at their support guide).
  • Once you have enabled the Dev Hub in your org, navigate to the Scratch orgs and dev hubs page, under My Salesforce Connections.

On the Salesforce tab, and click 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.

  • Under the Manage SFDX dev hubs section, click  Select SFDX dev hub and choose your Dev Hub org from the list of your current orgs
  • Your connected Dev Hub will now visible below Manage SFDX dev hubs

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 either Metadata deployments or Data deployments and click on SFDX scratch org. You will be able to see your connected Dev Hub from 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. This usually takes less than 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 orgs - no passwords 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?