What is a “Scratch Org”

As per definition from Salesforce developer portal:

The scratch org is a source-driven and disposable deployment of Salesforce code and metadata. A scratch org is fully configurable, allowing developers to emulate different Salesforce editions with different features and preferences. 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.

As the definition states that the Scratch Orgs are disposable deployments which means they are not permanent and are great for temporary deployments. This can help in boosting developer productivity and easier for team collaboration especially for automating test & deployment. But the scratch orgs typically get automatically disposed off in 7 days. The max you can keep them for is 30 days.

Developer can share the scratch org with other members of the teams and develop together.

To be able to work with Scratch Orgs, you should first enable the Dev Hub in your business / production org.

Steps to create scratch org:

Pre-requisite:

  1. Open VsCode
  2. Open Command Palette (Ctrl + Shift + P) and choose: SFDX: Create Project with Manifest
  3. Choose ‘Standard’ as project template.
  4. Enter name for the project.
  5. When asked, select a folder on the disk to save your project to.
    1. VsCode would run the CLI command to create a basic structure for your project.
  6. Open Command Palette and choose ‘SFDX: Open Default Org’. This should launch a new browser window and logging you to the new scratch org’s setup section.
  7. At this point you can start creating the code artifacts. For example: to create an apex class, open Command Palette and choose ‘SFDX: Create Apex Class’, specify the file name and press enter. This would create a new apex class for you.
List of commands to generate various other artifacts in scratchorg

Push & Pull Code

  1. To push your code to the scratch org, open Command Palette and choose ‘SFDX: Push Source to Default Scratch Org’.
  2. If everything ran successfully you should see your custom apex class in the scratch org (setup à Custom Code à Apex Classes).
  3. This way you can build various other code artifacts like Trigger, Lightning Component, Lightning Apps, Visualforce Pages etc. and deploy them to scratch org and test.
  4. Like push, you can also pull the code from scratch org. From the Command Palette, choose ‘SFDX: Pull Source from Default Scratch Org’. This should pull all the code from the org to your local system.

For more information follow the salesforce documentation here.

Salesforce

Scratch Org

Gallery

One thought on “Scratch Org

  1. Pingback: Scratch Org — Hello “Blog”! – SutoCom Solutions

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s