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

5-minute read
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 times in the Trailblazer Community), and finding them in the Metadata API Developer Guide can be tricky. Some settings have cryptic names, whereas some others 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 all settings again
  • 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:

Next 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:
[fusion_syntax_highlighter theme=”hopscotch” language=”javascript” line_numbers=”no” line_wrapping=”” copy_to_clipboard=”yes” copy_to_clipboard_text=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” font_size=”” border_size=”” border_color=”” hue=”” saturation= » » lightness = » » alpha = » » border_style = » » background_color = » #000000″ line_number_background_color = » » line_number_text_color = » » margin_top = » » margin_right = » » margin_bottom = » » margin_left = » »]InVzZXJNYW5hZ2VtZW50U2V0dGluZ3MiOiB7CsKgIMKgICJwZXJtc2V0c0luRmllbGRDcmVhdGlvbiI6IHRydWUKfQ==[/fusion_syntax_highlighter]
Your Scratch Org definition file should then look like this:
[fusion_syntax_highlighter theme=”hopscotch” language=”javascript” line_numbers=”no” line_wrapping=”” copy_to_clipboard=”yes” copy_to_clipboard_text=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” font_size=”” border_size=”” border_color=”” hue=”” saturation= » » lightness = » » alpha = » » border_style = » » background_color = » #000000″ line_number_background_color = » » line_number_text_color = » » margin_top = » » margin_right = » » margin_bottom = » » margin_left = » »]ewogICJvcmdOYW1lIjogIlRleGXDryIsCiAgImVkaXRpb24iOiAiRGV2ZWxvcGVyIiwKICAiZmVhdHVyZXMiOiBbIkVuYWJsZVNldFBhc3N3b3JkSW5BcGkiX SwKICAic2V0dGluZ3MiOiB7CiAgICAibGlnaHRuaW5nRXhwZXJpZW5jZVNldHRpbmdzIjogewogICAgICAiZW5hYmxlUzFEZXNrdG9wRW5hYmxlZCI6IHRydWUKI CAgIH0sCiAgICAibW9iaWxlU2V0dGluZ3MiOiB7CiAgICAgICJlbmFibGVTMUVuY3J5cHRlZFN0b3JhZ2VQcmVmMiI6IGZhbHNlCiAgICB9LAogICAgInVzZXJN YW5hZ2VtZW50U2V0dGluZ3MiOiB7CiAgICAgICJwZXJtc2V0c0luRmllbGRDcmVhdGlvbiI6IHRydWUKICAgIH0KICB9Cn0=[/fusion_syntax_highlighter]
You can try to create a brand new Scratch Org from it and see for yourself that it's working!
That’s 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.

 

 

Also read on the blog