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

Enforce code standards with PMD

Developers working on a project usually set coding rules to have a standardized codebase. It is an important piece of the code maintainability, and it can be very easy …
March 2023
Advices
Business Analyst

Core qualities of a Business Analyst?

A common definition we are used to hear is that being a Business Analyst means to have a combination of both hard skills and soft skills. What does a …
June 2022
Advices
Image d'illustration d'une employée travaillant sur un ordinateur portable

Process builder and workflow make way to Flows (½)

Overview “If you can do it with a Workflow, then do it with a Process Builder, because everything a Workflow does, a Process Builder does it better”. If you …
March 2022
Advices

Day 22 : Salesforce new “Migrate To Flow tool” in Spring 22

As most of you already know, the workflow rules and process builders are planned to be retired in 2023 (no precise date defined so far). Today, I’m going to …
December 2021
Advices

Day 18 : Fake callout responses for test classes !

Hello everybody ! Today let’s talk about Apex tests classes in Salesforce. Everyone loves a good test class, and Salesforce makes it official by requiring to have a minimum …
December 2021
Advices
Wrapped up gifts

Day 13 : CI/CD Salesforce deploys only delta with github actions

Most projects today configure the CI/CD to deploy all metadata from the git repository, even those that haven’t been changed. When you are on a small project, you don’t …
December 2021
Advices