Uncovering Salesforce Settings: A Step-by-Step Guide for Scratch Orgs

By

5 minutes de lecture
Scratch orgs

Today, it’s pretty easy to build your Scratch Org definition file when you know what Settings you want to activate, as they are mapped with the same setting names from the Metadata API. But what happens when you want to activate a new setting that has either not yet been documented or that has a weird technical name that you can’t relate to the actual feature ? Let’s have a look on how to find it !

Give me that setting

You may be very excited by new features, be it the new option to let you set Field-Level Security for a field on Permission Sets instead of Profiles during field creation, or the powerful new Lightning Web Security. But how do you activate them in your Scratch Orgs ? As you can see, the related setting name isn’t always listed in the Release Notes (LWS has been added recently after being asked many time in the Trailblazer Community), and finding them in the Metadata API Developer Guide can be tricky. Some settings have cryptic names, whereas some other won’t be documented until the release is out in Production environments or the feature becomes GA.

What I do is actually pretty simple:

  • create an empty SFDX project
  • retrieve all Settings
  • commit everything with git
  • change the setting I want in the Scratch Org
  • retrieve again all Settings
  • git will just highlight the change you want, which will be the setting you were looking for

This is pretty easy to do, whether you’re a developer or an App Builder. Let’s do it with a real life scenario.

Hands on !

Note: to follow this tutorial, you’ll need to have git, the SFDX CLI, VS Code and the Salesforce Extension Pack. If you are not familiar with these or with development with Scratch Org, I suggest you first take the App Development with Salesforce DX Trailhead module. For learning how to use git, I recommend the Git and GitHub Basics one.

We’ll go with the FLS on Permission Sets at field creation example here.

First create an empty project, either by running SFDX: Create Project from the Command Palette in VS Code, or by running the command line sfdx force:project:create -n find-sfdx-setting.

Once your project open in VS Code, initialize your git repository by running git init from the terminal, or clicking Initialize Repository in the git section of VS Code.

Scratch Org

Create a Scratch Org by running Command + Shift + P to open the Command Palette, select Create a Default Scratch Org... and accept all default  values (you could select 1 for Scratch Org expiration as you won’t use it for more than 10mn anyway).

Then, once the Scratch Org is created, retrieve all existing Settings by running the command sfdx force:source:retrieve --metadata Settings.

Scratch Org

Save all these changes to git, by adding them to your staged changes and committing them. Either do it via the command line (git add . and git commit -m 'My commit message' or use the git extension in VS Code.

First add all your changes by clicking on the + button on the Changes line:

Scratch Orgs

And then add a commit message and click on the Commit button:

Nexts steps with Scratch Orgs

Now just open the Scratch Org, go to User Management Settings and enable the Field-Level Security for Permission Sets during Field Creation setting.
Scratch Orgs
Go back to VS Code, and retrieve the Settings again (sfdx force:source:retrieve --metadata Settings).
Git will highlight the setting that has changed, which is the one you want to add to your Scratch definition file (config/project-scratch-def.json):
You can see the setting you’re looking for is located under UserManagementSettings/permsetsInFieldCreation.
As explained in the documentation,  you can use this setting hierarchy as is to update your Scratch Org definition file, just moving it to lower camel case.
So in this case, just adding this would make your next Scratch Org get the Field-Level Security for Permission Sets during Field Creation enabled automatically:
Copy to Clipboard
Your Scratch Org definition file should then look like this:
Copy to Clipboard
You can try to create a brand new Scratch Org from it and see by yourself that it’s working !
Thats it ! As you can see this is pretty easy to do, and will let you find any setting you want in just a few minutes.

 

 

Read more posts