Saturday, February 18, 2023

What are scratch orgs in salesforce and how to create scratch org in salesforce?

In this blog post we are going to discuss about scratch orgs in salesforce.

Basic Details:

Scratch org is a disposable salesforce org used for development and testing. 

By default, they do not contains sample data, workflows, profiles, permission sets, apex classes, triggers, pages. In short scratch orgs are empty and they don’t contain much of the sample metadata that you get when you sign up for an org, such as a Developer Edition org.

Each developer could have their own scratch org to increase productivity or you can share the scratch org configuration file with other team members, so you all have the same basic org in which to do your development. 

Scratch orgs have these storage limits:

200 MB for data
50 MB for files

Scratch Org Expiration Policy:
  1. Scratch org can be created for a maximum of 30 days after which scratch org gets deactivated. 
  2. You can select a duration from 1 through 30 days at the time of creation. 
  3. Default duration for Scratch org is 7 days. 
  4. After the scratch org has expired, you can’t restore it.
On Which Salesforce Instances Are Scratch Orgs Created?

Scratch orgs are created from Dev Hub. Your Dev Hub org is often your production org or a separate developer org. Your Dev Hub edition determines how many scratch orgs you can create or how many can be active at a given time.

What are differences between Scratch Org vs Sandbox?

The main difference between scratch org and sandbox is your sandbox is linked to your production org and it copy metadata from production environment and can contains records copied from production environment in case of partial or full copy sandbox whereas by default scratch org is empty.

Scratch Org Creation:

Before you create a scratch org:
  • Set up your Salesforce DX project
  • Authorize the Dev Hub org
  • Create the scratch org definition file
The Dev Hub org allows you to create, delete, and manage your Salesforce scratch orgs. After you set up your project on your local machine, you authorize with the Dev Hub org before you can create a scratch org.

You can also authorize other existing orgs, such as sandbox or packaging orgs, to provide more flexibility when using CLI commands. For example, after developing and testing an application using scratch orgs, you can deploy the changes to a centralized sandbox. Or, you can export a subset of data from an existing production org and import it into a scratch org for testing purposes.

For more details on how to "Authorize the Dev Hub org" please visit How to authorize the dev hub org in salesforce?

Now press CTRL+SHIFT+P and search for "Create a Default Scratch org.." and click it and select the file available as shown in the below images.

visual studio code salesforce setup

how to use visual studio code for salesforce

Specify the name and the days after which the Scratch org will expire. Now we can see that the Scratch org is getting created as shown in below image.

how to use visual studio code for salesforce

After the Scratch org is created successfully press CTRL+SHIFT+P  and type "SFDX:Open Default Org ". It will open the Scratch org in new console as shown below.

Scratch org in Salesforce using Visual Code Studio


  1. Great article! 😍👍 I've always wondered what scratch orgs were and now I have a better understanding thanks to your clear and concise explanation. 🙌🤓 The step-by-step instructions for creating a scratch org are especially helpful. 🚀💻 Looking forward to trying this out!

  2. Thank you for sharing good information about scratch orgs. This is the best information for me which I learn. This improves my thinking and problem-solving skill.

  3. Nice article, thank you for your work!