Scratch org is a new concept coming packed with the latest DX release of Salesforce, which is primarily a disposable and source-driven deployment environment for metadata and code. This makes the developers’ job much easier and also facilitates the automation of testing and deployment.
Scratch org is custom configurable and allows the developers and testers to emulate various Salesforce editions having different preferences and features. Now, Scratch org is one of the key components of the Salesforce DX suite, which puts forth an open developer experience to develop and manage the Salesforce apps through their complete lifecycle.
Developers can share their configured scratch org files with other members of the team in a corporate development environment so that all involved can share the same org in which they develop. Scratch orgs are now available in various editions as:
- Professional etc.
Advantages of Scratch org
Scratch org can effectively improvise the productivity of the developers and effectively collaborate with the development process by facilitating CI (continuous integration) and automated testing. Developers can use the IDE or CLI to open scratch org in any browser. There is no need for a, and you can also spin up a scratch org whenever needed for.
- Starting a new development project.
- Starting a new module in a project.
- Test a feature.
- Run automated testing.
- Perform the development tasks in a given org.
- Build from scratch in a fresh org.
Salesforce partners can create partner editions of Scratch org like
- Partner Enterprise
- Partner Developer
- Partner Professional
- Partner Group etc.
To ensure peak performance, scratch org allocations are determined by your Dev Hub. Later, such allocations will determine the number of scratch orgs you are allowed to create daily and how much can be kept active as pre-programmed scratch orgs may get deleted along with all the associated records from the Dev Hub org during the expiry of a scratch org.
Usually, a scratch org may get expired in 7 days if you haven’t set any custom duration while creating it. Standard scratch orgs also have storage limits as 200 MB data and 50 MB files.
Scratch Org essentials
Here is some essential scratch org terminology as defined by Flosum.com experts which the beginner Salesforce DX developers need to know. Definition File – It is the blueprint of a new scratch org created. This mimics the actual shape of the org which you use in development life cycle like packaging, sandbox, or
Definition file also consists of the configuration values, which defines the scratch shape and structure. Scratch Org Salesforce Release – During release transition of Salesforce, it is possible for you to specify the release on creating a scratch org.
Project Structure – Every Salesforce DX projects may have a unique project structure as well as source format. The DX source may use a unique set of files and specific file extensions while using the metadata API.
Push Source – Once after changing the source file, you can sync all the changes to the newly created scratch org by simply pushing changed source.
Assigning Permission Set – Once on creating scratch org and push source is done, you may give the user access to the application, especially if the app contains some objects.
Adding data to Scratch Org – you need a small set of data at stock for testing in development orgs. Scratch orgs used to come with the same sample data set based on the edition.
In the case of Developer edition, orgs may typically have 10 to 15 records for standard objects like Contact, Account, Lead, etc.
Pulling source from Scratch Org to the current project – once the initial push is done, then the Salesforce DX may track all the changes between the local files and the scratch org.
Tracking changes between Scratch Org and project – While doing development, you can easily change the local files in the given project directory in the scratch org, remotely.
Before pushing any local changes to scratch org or changing local Salesforce DX, it is ideal to see what all changes are made by you.
Users in Scratch Org – There is an administrator user for Scratch Org by default. This admin user is adequate for all the testing tasks. However, sometimes, you may have some other users also to test various permissions sets and profiles.
Managing Scratch Orgs from the Dev Hub
To work effectively with Scratch Orgs, one should enable the Dev Hub at the first point in the production org or a business org. One can also view or delete the scratch orgs and all the associated requests from Dev Hub. You may better use the CLI (command line interface) of Salesforce DX for creation of scratch orgs.
There are two ways to effectively manage the scratch org as using the CLI command line or the more user-friendly graphical interface offered by Salesforce.
Enabling Dev Hub
You have first to enable the Dev Hub to create and manage the scratch orgs, which you can do from the command line interface. As we have seen above, Scratch orgs as the disposable orgs which will help in both development as well as testing. It is fully safe to enable a Dev Hub in both business and production orgs, which will not cause any customer or performance issues. A typical Dev Hub comprises of many objects which need permissions to allow the administrators to control the accesses to users and orgs.
Some additional factors to note about Scratch Org are:
- It is possible to create six scratch orgs per day along with its packaged versions. At a time, 3 scratch orgs can be kept active.
- On Developer edition, orgs may get deactivated if kept inactive for 365 days.
- It is possible to custom define the namespace at Developer edition ScratchOrg which are not your Dev Hub.
If you are planning to custom create the package versions or to run some continuous integration tasks, then you can best use the business or production org as Dev Hub, which has a higher limit for scratch org. A beginner user of Salesforce DX need to be thorough with Dev Hub at the first point to better management the projects and hope this information helped you for it.