Is there any way how to automatically enable "Data Protection and Privacy" option during creation of scratch org (in definition file)?

Data Protection and Privacy

I didn't found any mention about this metadata in Metadata API at all. Is it already supported?

We have implemented some logic that is dependent on Individual object and I can't push converted dx source into scratch org with this option disabled.


You can set this inside the org preferences.


<?xml version="1.0" encoding="UTF-8"?>
<OrgPreferenceSettings xmlns="http://soap.sforce.com/2006/04/metadata">

Easiest way to get this file is to add it to your package.xml under Settings if you are pulling from a sandbox or to actually create it as above and push into a scratch org - when you pull you should get all the other settings in there as well.

  • Adding this file causes my push to fail against my scratch org. Is this the correct format? Jun 17 '19 at 21:25
  • Edited above to show how the whole file would look like and how to pull/retrieve this from a sandbox or scratch org. Jun 19 '19 at 7:49
  • This was perfect, I wish I could mark the answer as accepted for the OP. Thank you! Jun 19 '19 at 17:08
  • Glad I could help! Jun 20 '19 at 11:28

The Data Protection and Privacy preference can be automatically enabled via the scratch org definition file (e.g. project-scratch-def.json) using the settings.orgPreferenceSettings.consentManagementEnabled property.

    "settings: {
        "orgPreferenceSettings": {
            "consentManagementEnabled": true

However, according to the Winter '20 Release Notes, the ConsentManagementEnabled field on the OrgPreferenceSettings metadata type will be moved to enableConsentManagementEnabled on PartyDataModelSettings instead, so be sure to update your configuration file in the future.

    "settings: {
        "partyDataModelSettings": {
            "enableConsentManagementEnabled": true

The ability to define org preferences in the scratch org definition file is available in Winter ’19 and later. This is detailed in the Scratch Org Settings section of the Scratch Org Definition Configuration Values documentation. You can also find a list all settings in the Settings Metadata API documentation. Be sure to use lower-case camel case when adding to the scratch org definition file.


It's not possible when push it to the scratch org and it's the expected behavior because Data Protection and Privacy option should be enable in the org when it needed. I have also written some logic behind the Individual object and can do something like below to overcome the issue,

When you do anything in the Individual object in your logic just check whether the Individual object which means the Data Protection and Privacy option is enabled in your org and if so do what you need.

It won't give any error while push the code to your scratch org but you have to enable the Data Protection and Privacy option in your org to execute the following logic which means your logic.

Boolean isIndividualEnable = Schema.getGlobalDescribe().containsKey('Individual');
if(isIndividualEnable == true) {
    Map <String, Schema.SObjectType > sObjects = Schema.getGlobalDescribe();
    Schema.SObjectType individualType = sObjects.get('Individual');
    Map<String, Schema.SObjectField> mSourceFields = individualType.getDescribe().fields.getMap();
    SObject individualObject01 = individualType.newSObject();
    SObject individualObject02 = individualType.newSObject();
    individualObject01.put(mSourceFields.get('Name'), 'Individual 1');
    individualObject02.put(mSourceFields.get('Name'), 'Individual 2');

    List<SObject> lstIndividual = new List<SObject>();
    insert lstIndividual;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.