This repo was created in response to this question on StackExchange:
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?
These instructions handle two steps:
- Setting the User Interface setting of
Enable "Set Audit Fields upon Record Creation" and "Update Records with Inactive Owners" User Permissions
- Assigning a permission set that adds this setting to the default user
- In the source org
- Run
sfdx force:source:retrieve -m Settings:Security
- Search the retrieved file for
enableAuditFieldsInactiveOwner
and set the value totrue
. Save the file.
- Run
- 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]
- Run
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.
- Simple security settings file with the audit fields setting enabled
- Permission set that allows "set audit fields upon creation"