6

We wish to create a scratch org that has the "Enable "Set Audit Fields upon Record Creation" and "Update Records with Inactive Owners" User Permissions" setting checked.

Is there a scratch org definition file option available to do this that I'm not seeing. Or failing that is there a programmatic way of setting the setting.

1
  • Appears to be a duplicate of Metadata for User Interface options which is unanswered. Note, when you do a source:pull after enabling those Setup features, only the NameSettings is retrieved from the User Interface configuration. Github issue was opened in Dec '18 but has been closed without solution.
    – TSmith
    Nov 26, 2019 at 16:30

2 Answers 2

6

What to do

I wrote out instructions in this GitHub repo, including sample files if you need them.

  1. In the source org
    • Run sfdx force:source:retrieve -m Settings:Security
    • Search the retrieved file for enableAuditFieldsInactiveOwner and set the value to true. Save the file.
  2. In a new scratch org
    • Run sfdx force:source:deploy -m Settings:Security immediately after creating the scratch org
    • Run sfdx force:source:push as usual
    • If needed, assign any needed permission sets using sfdx force:user:permset:assign --permsetname [yourauditfieldpermset]

Why should this work?

Basically, you need to enable the set audit fields setting for the org before you attempt to add it to any permission sets or profiles. If you try to enable the setting and push the permission set at the same time, it'll fail silently--the rest of the permission set will go through, but not that piece.

3
  • Thanks Allison. Will give this a try. Nice thinking. Dec 3, 2019 at 8:56
  • This just saved me a ton of head scratching! Thank you May 24, 2020 at 0:23
  • Life pro tip: you can use packageDirectories to stage push of your security settings and profie/permset. They are now pushed in order they are specified in sfdx-project.json.
    – dzh
    Nov 4, 2020 at 7:04
4

You can configure your project-scratch-def.json like this:

{
  "orgName": "Scratch", 
  "edition": "Developer",
  "features": [],
  "settings": {
      "securitySettings": {
        "enableAuditFieldsInactiveOwner": true
      }
  }
}

This will create your scratch org with this setting pre-configured so you do not need more steps.

In here full documentation of security settings.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .