Newer Version Available
Build Your Own Scratch Org Definition File
The settings and configuration options associated with a scratch org determine its shape, including:
- Edition—The Salesforce edition of the scratch org, such as Developer, Enterprise, Group, or Professional.
- Add-on features—Functionality that is not included by default in an edition, such as multi-currency.
- Settings—Org and feature settings used to configure Salesforce products, such as Chatter and Communities.
Setting up different scratch org definition files allows you to easily create scratch orgs with different shapes for testing. For example, you can turn Chatter on or off in a scratch org by setting the ChatterEnabled org preference in the definition file. If you want a scratch org with sample data and metadata like you’re used to, add this option: hasSampleData.
We recommend that you keep this file in your project and check it in to your version control system. For example, create a team version that you check in for all team members to use. Individual developers could also create their own local version that includes the scratch org definition parameters. Examples of these parameters include email and last name, which identify who is creating the scratch org.
Scratch Org Definition File Name
You indicate the path to the scratch org configuration file when you create a scratch org with the force:org:create CLI command.
- If you’re using Salesforce CLI on the command line, you can name this file whatever you like and locate it anywhere the CLI can access.
- If you’re using Salesforce Extensions for VS Code, make sure that the scratch org definition file is located in the config folder and its name ends in scratch-def.json.
If you’re using a sample repo or creating a Salesforce DX project, the sample scratch org definition files are located in the config directory. You can create different configuration files for different org shapes or testing scenarios. For easy identification, name the file something descriptive, such as devEdition-scratch-def.json or packaging-org-scratch-def.json.
Scratch Org Definition File Options
Here are the options you can specify in the scratch org definition file:
| Name | Required? | Default If Not Specified |
|---|---|---|
| orgName | No | Company |
| country | No | Dev Hub's country. If you want to override this value, enter the two-character, upper-case ISO-3166 country code (Alpha-2 code). You can find a full list of these codes at several sites, such as: https://www.iso.org/obp/ui/#search. This value sets the locale of the scratch org. |
| username | No | test-unique_identifier@example.com |
| adminEmail | No | Email address of the Dev Hub user making the scratch org creation request |
| edition | Yes | None. Valid entries are Developer, Enterprise, Group, or Professional |
| description | No | None. 2000-character free-form text field. The description is a good way to document the scratch org’s purpose. You can view or edit the description in the Dev Hub. From App Launcher, select Scratch Org Info or Active Scratch Orgs, then click the scratch org number. |
| hasSampleData | No | Valid values are true and false. False is the default, which creates an org without sample data. |
| language | No | Default language for the country. To override the language set by the Dev Hub locale, see Supported Languages for the codes to use in this field. |
| features | No | None |
| release | No | Same Salesforce release as the Dev Hub org. Options are preview or previous. Can use only during Salesforce release transition periods. |
| settings | No | None |
| objectSettings | No | None. Use objectSettings to specify object-level sharing settings and default
record types. To successfully install in a scratch org, some packages require that
you define object-level sharing settings and default record types. The
objectSettings option is a map. Each key is the lowercase name of an object, such as
opportunity or account. The definition for each key is also a map with two possible values:
|
| <custom field API name> | No | None. Useful for Dev Ops use cases where you want to track extra information on the ScratchOrgInfo object. First, create the custom field, then reference it in the scratch org definition by its API name. |
| sourceOrg | No | None. 15-character source org ID. Use only if you are using Org Shape for Scratch orgs to create your scratch org. See Create a Scratch Org Based on an Org Shape. |
Sample Scratch Org Definition File
1{
2 "orgName": "Acme",
3 "edition": "Enterprise",
4 "features": ["Communities", "ServiceCloud", "Chatbot"],
5 "settings": {
6 "communitiesSettings": {
7 "enableNetworksEnabled": true
8 },
9 "mobileSettings": {
10 "enableS1EncryptedStoragePref2": true
11 },
12 "omniChannelSettings": {
13 "enableOmniChannel": true
14 },
15 "caseSettings": {
16 "systemUserEmail": "support@acme.com"
17 }
18 }
19}Some features, such as Communities, can require a combination of a feature and a setting to work correctly for scratch orgs. This code snippet sets both the feature and associated setting.
1"features": ["Communities"],
2 "settings": {
3 "communitiesSettings": {
4 "enableNetworksEnabled": true
5 },
6 ...Create a Custom Field for ScratchOrgInfo
You can add more options to the scratch org definition to manage your Dev Ops process. To do so, create a custom field on the ScratchOrgInfo object. (ScratchOrgInfo tracks scratch org creation and deletion.)
- In the Dev Hub org, create the custom field.
- From Setup, enter Object Manager in the Quick Find box, then select Object Manager.
- Click Scratch Org Info.
- In Fields & Relationships, click New.
- Define the custom field, then click Save.
- After you create the custom field, you can pass it a value in the scratch org definition
file by referencing it with its API name.
Let’s say you create two custom fields called workitem and release. Add the custom fields and associated values to the scratch org definition:
1{ 2 "orgName": "MyCompany", 3 "edition": "Developer", 4 "workitem__c": "W-12345678", 5 "release__c": "June 2018 pilot", 6 7 "settings": { 8 "omniChannelSettings": { 9 "enableOmniChannel": true 10 } 11 } 12} - Create the scratch org.
Set Object-Level Sharing Settings and Default Record Types
To install successfully, some packages require that you define object-level sharing settings and default record types before installation. Set the sharing settings and default record types with objectSettings. In this sample scratch org definition file, we set a sharing model and a default record type for opportunity, and a default record type for account.
1{
2 "orgName": "MyCompany",
3 "edition": "Developer",
4 "features": ["Communities", "ServiceCloud", "Chatbot"],
5 "settings": {
6 "communitiesSettings": {
7 "enableNetworksEnabled": true
8 }
9 }
10 "objectSettings": {
11 "opportunity": {
12 "sharingModel": "private",
13 "defaultRecordType": "default"
14 },
15 "account": {
16 "defaultRecordType": "default"
17 }
18 }
19}