SfSkills Domains Docs GitHub

Home / security / encrypted-field-query-patterns

encrypted-field-query-patterns

Design SOQL, filters, reporting, and indexes against Shield Platform Encryption fields. Trigger keywords: Shield Platform Encryption, encrypted field query, probabilistic vs deterministic encryption, encrypted SOQL filter. NOT for Classic Encryption (deprecated), field-level security policy, or tenant secret k — use security/platform-encryption.

Open the skill folder on GitHub


Encrypted Field Query Patterns

The Core Constraint

Shield Platform Encryption changes SOQL semantics. Plan the queries FIRST, then choose the encryption scheme. Reversing that order means rebuilding schemas later.

Scheme Matrix

SchemeUse CaseSOQL Support
ProbabilisticMax security, display-onlyNO filter, NO sort, NO group by, NO index
Deterministic (case-sensitive)Exact match required=, IN, joins, unique indexes; NO range, NO LIKE
Deterministic (case-insensitive)Exact match, case-agnostic=, IN; NO range, NO LIKE

No scheme supports LIKE on encrypted fields. No scheme supports range (>, <, BETWEEN) operators.

Decision By Query Pattern

QueryScheme
Display only (never filter)Probabilistic
Lookup by exact valueDeterministic (case-sensitive if value is case-stable)
Customer search by name (case-agnostic)Deterministic case-insensitive
Range query (date, amount)Do not encrypt — use field-level security + masking
LIKE searchDo not encrypt — or store a derived hash/index field
Sort by fieldOnly if you rely on display order, not SOQL ORDER BY

Indexing

Aggregation And Reporting

Apex Patterns

Shield Platform Encryption decrypts transparently. Any user with field-level READ access on the field receives plaintext — in Apex, in SOQL results, in reports, and in the UI. There is no separate "show me the plaintext" permission you can withhold.

Shield vs Classic — do not merge these. The "View Encrypted Data" permission belongs to Classic Encryption, the legacy Encrypted Text custom field type, where a user without it sees *********. Shield Platform Encryption has not used that permission since Spring '17. Removing "View Encrypted Data" does not mask a Shield-encrypted field — the user still sees plaintext if FLS grants read. Guidance that says otherwise tells a reader data is protected when it is not.

Plaintext visibility for Shield is restricted with field-level security (profiles / permission sets), page layouts, and sharing. Encryption is an at-rest control, not an authorization control. Plan for:

  1. Enumerate every query / report / list view / filter that touches

    each candidate field.

  2. Classify each query: exact, range, LIKE, aggregate, display.
  3. Apply the scheme matrix. Flag fields where encryption blocks a

    required query.

  4. For blocked fields, decide: drop the requirement, skip encryption,

    or derive a hashed index field (one-way).

  5. Request custom indexes on deterministic fields used as filters.
  6. Test with a user who has FLS read on the field and one who does not

    — Shield gates plaintext on FLS, not on "View Encrypted Data".

  7. Document the scheme per field in a schema decision log.

Official Sources Used

Package files