Platform encryption configure

From forcedotcom/sf-skills · View interactive version

Platform encryption configure is an AI agent skill from the GitHub repository forcedotcom/sf-skills. Configure Salesforce Shield Platform Encryption — generate deployable encryption settings and encrypted-field metadata, and answer key-model and lifecycle questions. TRIGGER when: user wants to turn on deterministic encryption, encrypt a field, set up Cache-Only Keys, External Key Management, or rep

How to use this skill

Skill file

Configure Platform Encryption

Configures Salesforce Shield Platform Encryption by generating the metadata that turns it on and choosing the right settings: which encryption scheme a field should use, which key-management model fits a requirement, and how the tenant-secret lifecycle works. This is a hybrid skill — it emits deployable *.settings-meta.xml / *.field-meta.xml where Platform Encryption exposes a real Metadata API surface, and returns grounded guidance where the operation is UI/REST-only.

Scope


Required Inputs

Gather or infer before proceeding:

If the request is clear, generate or answer immediately — do not interrogate the user.


Workflow

  1. Classify the request — deployable artifact vs guidance, using the Required Inputs above. Then scope the output to exactly what was asked:
  1. For field encryption — read references/encryption-schemes.md to choose the scheme, then load assets/encrypted-field.field-meta.xml as the starting template. Set encryptionScheme to exactly one of the four valid enum values (see the reference). Only Deterministic* schemes are filterable.

> Write the field file at the SFDX source path, not the root. A *.field-meta.xml must live at objects/<ObjectApiName>/fields/<FieldApiName>__c.field-meta.xml (e.g. objects/Patient__c/fields/Diagnosis_Notes__c.field-meta.xml) — the object folder uses the object's API name (Patient__c for a custom object, Contact for a standard one) and the file is named after the field API name. Emitting the file at the repo root, in a flat directory, or under any other folder is a structural miss even when the XML itself is correct.

  1. For org-level encryption settings — load assets/PlatformEncryption.settings-meta.xml (deterministic encryption, field-history encryption, MEK permission) or assets/EncryptionKey.settings-meta.xml (Cache-Only, EKM, Data 360, transactional DB, replay detection). Read references/key-models.md before setting any key-model field.

> Name the output file after the Settings member, not the root element, and write it under settings/. A Settings file must be settings/<member>.settings-meta.xml, where <member> is the org's metadata member name — EncryptionKey (root <EncryptionKeySettings>) and PlatformEncryption (root <PlatformEncryptionSettings>). Put it in the settings/ source folder (e.g. settings/EncryptionKey.settings-meta.xml), not the repo root. Naming the key-settings file Encryption.settings-meta.xml or EncryptionKeySettings.settings-meta.xml fails deployment with "The object '…' of type Settings metadata does not exist."

> Cache-Only Keys and replay detection are a one-way dependency, not an auto-enable. You may set enableReplayDetection only after enableCacheOnlyKeys is true; enabling Cache-Only does not turn replay detection on by itself. An org can validly run Cache-Only with replay detection off.

  1. For tenant-secret operations (rotate, destroy, BYOK upload, Cache-Only callout setup) — read references/tenant-secret-lifecycle.md. These are UI/REST-only; capture the guidance in the single markdown answer file, not a deployable metadata file.
  1. Validate any generated settings XML — run scripts/validate-encryption-metadata.sh with the file path as its argument, and fix anything it reports. It checks the replay-detection dependency and the encryptionScheme enum deterministically.
  1. Compare against the worked example — verify a generated EncryptionKeySettings file against examples/cache-only-keys.settings-meta.xml.

Rules / Constraints

| Constraint | Rationale |

|-----------|-----------|

| encryptionScheme must be exactly one of CaseInsensitiveDeterministicEncryption, CaseSensitiveDeterministicEncryption, None, ProbabilisticEncryption | These are the only values the Metadata API accepts (CustomField, API 44.0+); any other string fails deployment. |

| Set enableReplayDetection only when enableCacheOnlyKeys is true | The contract is "Requires enableCacheOnlyKeys=true before setting enableReplayDetection to true" — a one-way dependency. |

| Use deterministic schemes only when the field must be filtered, sorted, or grouped | Probabilistic is stronger but non-filterable; deterministic trades some cryptographic strength for queryability. |

| Never claim a filter/sort/group on a probabilistically-encrypted field silently returns zero rows | The platform rejects the query with INVALID_FIELD (see gotchas); telling the user it "returns nothing" is factually wrong. |

| Do not emit enableExternalKeyManagement — the field is canExternalKeyManagement | The WSDL element is canExternalKeyManagement; the sample in some docs uses a non-existent element name. |

| Transactional-DB, EKM, and Data 360 key fields require API 63.0+ | canEncryptTransactionalDatabase, canExternalKeyManagement, canManageDataCloudKeys were introduced in 63.0. |

| A guidance question produces exactly one markdown answer file — never a deployable *.settings-meta.xml / *.field-meta.xml, and never a second doc | The answer file is the user's reference document — it persists in the workspace and can be shared or revised. Emitting a deployable metadata file for a guidance question is unsolicited configuration that could be accidentally applied; emitting no file leaves the user without a tangible deliverable. |

| An artifact request emits only the metadata file(s) asked for — no companion files | Adding a DEPLOYMENT_GUIDE.md/README.md/EXPLANATION.md or an extra settings file the user didn't request is noise. Prerequisites belong in a code comment inside the artifact, not a second file. |


Gotchas

| Issue | Resolution |

|-------|------------|

| Filtering/sorting/grouping on a probabilistically-encrypted field | The query is rejected with INVALID_FIELD: "field '<Name>' can not be sorted / filtered / grouped in a query call." Switch the field to a deterministic scheme if queryability is required. |

| Assuming Cache-Only Keys auto-enables replay detection | It does not. Set enableReplayDetection explicitly, and only after enableCacheOnlyKeys=true. |

| Case sensitivity in deterministic matching | CaseSensitiveDeterministicEncryption matches exact case; CaseInsensitiveDeterministicEncryption normalizes case. Choosing wrong silently breaks equality filters. |

| Confusing BYOK with BYOKMS/EKM | BYOK = you upload key material Salesforce stores; BYOKMS/EKM = key material stays in your external KMS. See references/key-models.md. |

| Using enableExternalKeyManagement element name | Wrong element. The field is canExternalKeyManagement. |

| Classic Encryption vs Shield | encryptionScheme is Shield only. EncryptedText custom fields are the legacy Classic feature and out of scope. |


Output Expectations

Deliverables depend on the request — produce exactly these and nothing more:

Do not add companion files (DEPLOYMENT_GUIDE.md, README.md, an extra org-settings file) that the user did not ask for — state prerequisites in a code comment inside the artifact, or inside the single answer file for guidance. File structure follows the templates in assets/.


Cross-Skill Integration

| Need | Delegate to |

|------|-------------|

| A custom field with no encryption | platform-custom-field-generate |

| The raw Metadata API type/field reference | platform-metadata-api-context-get |


Reference File Index

| File | When to read |

|------|-------------|

| assets/encrypted-field.field-meta.xml | Before generating an encrypted custom field |

| assets/PlatformEncryption.settings-meta.xml | Before generating org encryption-policy settings (member PlatformEncryption) |

| assets/EncryptionKey.settings-meta.xml | Before generating key-management settings — Cache-Only, EKM, Data 360 (member EncryptionKey) |

| references/encryption-schemes.md | When choosing deterministic vs probabilistic, or explaining encrypted-field query behavior |

| references/key-models.md | When configuring or explaining BYOK / BYOKMS / EKM / Cache-Only key models |

| references/tenant-secret-lifecycle.md | When the user asks about key rotation, destruction, or BYOK upload |

| examples/cache-only-keys.settings-meta.xml | To verify a generated Cache-Only key-settings file |

| scripts/validate-encryption-metadata.sh | After generating any settings XML — validates the replay dependency and scheme enum |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.