1

I get the following error when pushing my source to a scratch org.

Deterministic encryption not available

I have a permission set assign to my scratch org user that gives me ManageEncryptionKeys.

I found through googling that I can create a key like so

sfdx force:data:record:create -s TenantSecret -v "Description=scratch"

I then can go to Setup > Security > Encryption > Advanced Settings, and see

enter image description here

What am I missing?

Update based on Mohith's answer. CLI results

Tylers-MacBook-Pro:test tyler$ sfdx force:source:push
*** Deploying with REST ***
Job ID | 0Af2D00000gqqH1SAI
SOURCE PROGRESS | ████████████████████████████████████████ | 2/2 Components
=== Pushed Source
STATE  FULL NAME             TYPE              PROJECT PATH
─────  ────────────────────  ────────────────  ─────────────────────────────────────────────────────────────────────────────────
Add    HealthCloudGA         InstalledPackage  force-app/main/default/installedPackages/HealthCloudGA.installedPackage-meta.xml
Add    System_Administrator  PermissionSet     force-app/main/default/permissionsets/System_Administrator.permissionset-meta.xml
Tylers-MacBook-Pro:test tyler$ sfdx force:user:permset:assign -n System_Administrator
=== Permsets Assigned
Username                       Permission Set Assignment
─────────────────────────────  ─────────────────────────
[email protected]  System_Administrator
Tylers-MacBook-Pro:test tyler$ sfdx force:data:record:create -s TenantSecret -v "Description=scratch"
Creating Record for TenantSecret... done
Successfully created record: 02G2D0000005KJjUAM.
Tylers-MacBook-Pro:test tyler$ sfdx force:mdapi:deploy -d src --json -w 10
{
  "status": 0,
  "result": {
    "checkOnly": false,
    "completedDate": "2021-03-21T06:27:57.000Z",
    "createdBy": "0052D000004tVtb",
    "createdByName": "User User",
    "createdDate": "2021-03-21T06:27:54.000Z",
    "details": {
      "componentSuccesses": [
        {
          "changed": "true",
          "componentType": "",
          "created": "false",
          "createdDate": "2021-03-21T06:27:56.000Z",
          "deleted": "false",
          "fileName": "src/package.xml",
          "fullName": "package.xml",
          "success": "true"
        },
        {
          "changed": "true",
          "componentType": "PlatformEncryptionSettings",
          "created": "false",
          "createdDate": "2021-03-21T06:27:56.000Z",
          "deleted": "false",
          "fileName": "src/settings/PlatformEncryption.settings",
          "fullName": "PlatformEncryption",
          "success": "true"
        }
      ],
      "runTestResult": {
        "numFailures": "0",
        "numTestsRun": "0",
        "totalTime": "0.0"
      }
    },
    "done": true,
    "id": "0Af2D00000gqr66SAA",
    "ignoreWarnings": false,
    "lastModifiedDate": "2021-03-21T06:27:57.000Z",
    "numberComponentErrors": 0,
    "numberComponentsDeployed": 1,
    "numberComponentsTotal": 1,
    "numberTestErrors": 0,
    "numberTestsCompleted": 0,
    "numberTestsTotal": 0,
    "rollbackOnError": true,
    "runTestsEnabled": false,
    "startDate": "2021-03-21T06:27:54.000Z",
    "status": "Succeeded",
    "success": true
  }
}
Tylers-MacBook-Pro:test tyler$ sfdx force:source:push
*** Deploying with REST ***
Job ID | 0Af2D00000gqr6QSAQ
SOURCE PROGRESS | █████████████████████████████████████░░░ | 281/306 Components
TYPE   PROJECT PATH                                                                                                      PROBLEM
─────  ────────────────────────────────────────────────────────────────────────────────────────────────────────────────  ────────────────────────────────────────────────────────────────────────────────────────
Error  marketing/main/default/objects/Account/fields/Birth_Date_Match__c.field-meta.xml                                  Deterministic encryption not available (3:13)
ERROR running force:source:push:  Push failed. 

Try this: 
Check the order of your dependencies and ensure all metadata is included.

1 Answer 1

4

Since enabling platform encryption settings is a bunch of steps, you will need to follow the below steps in order. You can automate this for your scratch org setup using a bash script or Node.js script

  1. Create scratch org sfdx force:org:create -f config/project-scratch-def.json --setalias dev1 --durationdays 1 --setdefaultusername --json

Note you will need to make sure you have PlatformEncryption as a feature in your scratch definition

"features": ["PlatformEncryption"],
  1. Assign a Permission Set that gives ManageEncryptionKeys to the user using below sfdx force:user:permset:assign --permsetname <permset_name> --targetusername <username/alias>

  2. Create the org tenant key required using below

    Create a tenant secret using sfdx force:data:record:create -s TenantSecret -v "Description=scratch".

  3. Create a folder called src in your project, create a subfolder settings and create the below file in the settings folder and name it as PlatformEncryption.settings with below content

     <?xml version="1.0" encoding="UTF-8"  standalone="yes"?>
     <PlatformEncryptionSettings xmlns="http://soap.sforce.com/2006/04/metadata">
      <enableDeterministicEncryption>true</enableDeterministicEncryption>
      <enableEncryptFieldHistory>true</enableEncryptFieldHistory>
     </PlatformEncryptionSettings>
    

You will need a package.xml file in your src folder as below

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
  <types>
    <members>PlatformEncryption</members>
    <name>Settings</name>
  </types>
 <version>51.0</version>
</Package>

The src folder will be part of your source and you don't need to automate this step as it is one time!

  1. Final step is to deploy these settings using the below

    sfdx force:mdapi:deploy -d src --json

  2. Create the org tenant key required using below

sfdx force:data:record:create -s TenantSecret -v "Description=scratch Type=DeterministicData"

5
  • How long will it take to deploy PlatformEncryption? Currently it saying it has a status of pending. How is your solution different from adding PlatformEncryption to my scratch org definition file?
    – Tyler Zika
    Commented Mar 21, 2021 at 1:02
  • Adding PlatformEncryption only enabled platform encryption and does not configure settings for it. If you add settings in the scratch-def file it won't work as it needs some prerequisite permissions. With an automation script, it should not take any time. Commented Mar 21, 2021 at 1:07
  • I did as you suggested and it didn't work. I copied and pasted the terminal results in my question. I'm using Org-Shape for my scratch org def. Do you think that could be causing the failure? I only have two features: HealthCloudUser, PlatformEncryption
    – Tyler Zika
    Commented Mar 21, 2021 at 6:36
  • 2
    I figured it out. You need to create the tenant like so: sfdx force:data:record:create -s TenantSecret -v "Description=scratch Type=DeterministicData" Feel free to update your answer!
    – Tyler Zika
    Commented Mar 21, 2021 at 6:55
  • @Andy Ray Where is it copied from? This is a genuine researched answer! Steps for creating a permission set is self understood in my opinion. Also I don't want to write a bash script since the choice of scripting this depends on someone's skillset. Many may prefer node, may may bash and some may prefer something else. Commented Oct 15, 2022 at 12:31

You must log in to answer this question.

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