What is Org Shape?
In this blog post, we will see what is an Org’s shape and how you can use this feature while creating scratch orgs.
What is the need for Org Shape?
Assume that you wanted to create a scratch org with certain features enabled. You might be thinking we do have a features option for that then what is the need for Org Shape? Well sometimes not all the features can be available in the features section, There are some features salesforce will enable when you reach out to them via support case. Those are some situations you can use Org shape and also when you want exact features, settings, limits, and licenses of production org you can use Org shape.
The main purpose of Org shape is to simplify the creation of Scratch Orgs that will support an entire replica(metadata) of production.
Org Shape: Features, settings, limits, and licenses determine what salesforce refers to as an org’s shape. This feature is available as a beta from winter 21
How to enable Org Shape?
Enabling the Org shape is very easy.
- Go to setup
- Enter org shape, Click Org shape under Development section
- Enable the option “Enable Org Shape for Scratch Orgs (Beta)”
- That’s it you are ready to use Org’s shape.
What is and isn’t included in Org Shape?
Included
- Edition
- Feature licenses
- User licenses
- Permission set licenses
- Organization Perms
- Organization Preferences
- Organization Values
Not Included
- Data
- Metadata
Before we jump on using org shape to create scratch org let’s understand some more feature platform offers.
Dev Hub
- Production Org that is enabled to create Scratch Orgs.
- Enable in Setup > Build > Develop > Dev Hub ( Please be noted that once you enable this features you can’t disable it)
Shape/Source Org
- Production or Packaging Org whose feature licenses, user licenses, perms, and preferences need to be replicated in a Scratch Org.
- Enabled in Setup > Build > Develop > Org Shape
- The feature is supported in all editions
- Can be enabled in a different org from the Dev Hub org, but Dev Hub needs to be authorized to access shape.
NOTE: You org can be a devhub and source org at a time. To clarify things a little bit.
- Assume that you have 2 orgs Org1 and Org2.
- In Org1 you have enabled the “dev hub” option and you can create scratch orgs using Org1.
- If you want to create scratch orgs using the Org2’s metadata then you need to enter the 15 digit dev hub org id under “Allow a Dev Hub org to create scratch orgs using this org’s shape. Enter each 15-character Dev Hub org ID on a separate line. A maximum of 50 Dev Hub orgs can be specified.” section of Org2. This way Org2 will hold the power.
Scratch Org
- A standalone, ephemeral org, development org that has a max lifespan of 30 days.
- It is created using a Dev Hub and it consumes a scratch org license in the Dev Hub org.
Let’s see how we can use this feature. In general, the project-scratch-def.json file looks like below.
where we need to mention the features and settings that we need to be present in scratch orgs. But when you are using the Org shape you can simply use the below project-scratch-def.json file to create scratch orgs.
{
“orgName”: “Salesforce”,
“sourceOrg”: “15-character source org ID”
}
Things to consider
- sourceOrg will take care of the edition of the scratch org. There is no point in mentioning the edition in json file.
- Features are additive in nature, You can include some other features which are not present in Source Org metadata. You can’t remove features that are present in source org.
- settings will override in case if you want them to enable/disable.
- Create a new project using VSCodecommand: sfdx force:project:create –projectname orgsShape –outputdir C:\Users\sreddyk\Desktop
- Authenticate to the devhub enabled org first and set it as the default devhub user name.commands:sfdx force:auth:web:login –setdefaultdevhubusername and sfdx force:config:set defaultusername=winter2021@force.com
- Create Org Shapecommand: sfdx force:org:shape:create -u winter2021@force.comYou can verify the Org Shape creation using the below soql query.SELECT CreatedById,CreatedDate,Description,Edition,Features,Id,IsDeleted,LastModifiedById,LastModifiedDate,LastReferencedDate,LastViewedDate,Name,Settings,Status,SystemModstamp FROM ShapeRepresentation where createddate=TODAY
- Check the Org Shape
command: sfdx force:org:shape:list - Change the definition file to looks like below{
“orgName”: “myorgShape”,
“sourceOrg”: “00DB00000005zy6”
} - Create a Scratch Orgcommand: sfdx force:org:create -f config\project-scratch-def.json –setalias myScratchOrg –durationdays 10 –setdefaultusername
You can check the ScratchOrgInfo Object for the status of the Scratch Org.
SELECT AdminEmail,AuthCode,ConnectedAppCallbackUrl,ConnectedAppConsumerKey,Country,CreatedById,CreatedDate,DeletedBy,DeletedDate,Description,DurationDays,Edition,ErrorCode,ExpirationDate,Features,HasSampleData,Id,Instance,IsDeleted,Language,LastLoginDate,LastModifiedById,LastModifiedDate,LastReferencedDate,LastViewedDate,LoginUrl,Name,Namespace,OrgName,OwnerId,Package2AncestorIds,Release,ScratchOrg,SignupCountry,SignupEmail,SignupInstance,SignupLanguage,SignupTrialDays,SignupUsername,SourceOrg,Status,SystemModstamp,Username FROM ScratchOrgInfo where createddate=TODAY
NOTE: Creation of Org shape is very fast and creation org Scratch org might take a considerable amount of time based on the source org/ devhub org metadata.
Let’s open the scratch and test some things.
NOTE: There might be some features/licenses that don’t match with production because certain things don’t make sense in scratch orgs ( Ex: Sandbox licenses in production doesn’t make sense having them in scratch org. )
You can try the other option where source org can be a different org ( Other than devhub org) and you can create a scratch based on the source org metadata. Please be noted that we definitely need a devhub org for creating scratch org.
Sample video Bite:
Thanks for reading, please do let me know in case of any questions/clarification I will try my best to answer them.
Comments
2 Comments
HI Sai charan, Thanks for the article. gives great insights..
im having an issue while trying to create scratch orgs with/without using ORG shapes.
im able to create scratch orgs but i dont see any custom metadata being created in scratch orgs. Do we need to do any additional work ? please let me know a way to get metadata get copied from production.
Thank you so much.
Hello Vamshi, Scratch Orgs are plain Vanilla Orgs you don’t get anything (No metadata and No actual data) after the scratch org got created. You need to manually load the data into the org. If this is repetitive work try automating it.
Leave a Comment