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
| Scheme |
Use Case |
SOQL Support |
| Probabilistic |
Max security, display-only |
NO 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
| Query |
Scheme |
| Display only (never filter) |
Probabilistic |
| Lookup by exact value |
Deterministic (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 search |
Do not encrypt — or store a derived hash/index field |
| Sort by field |
Only if you rely on display order, not SOQL ORDER BY |
Indexing
- Custom indexes on deterministic encrypted fields are supported for
equality filters.
- Standard indexes (lookup, master-detail) are not automatically present
on encrypted fields — request a custom index.
- Query selectivity degrades if the encrypted field has low cardinality
post-encryption.
Aggregation And Reporting
- GROUP BY on encrypted field: supported only with deterministic.
- SUM / AVG on an encrypted number: generally not supported — leave
aggregatable numerics unencrypted unless compliance requires.
- Reports with filters on encrypted fields: equality works for
deterministic; others fail at runtime.
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:
- Test users with FLS read granted and FLS read removed on each
encrypted field.
- Avoid logging encrypted values in
System.debug even when you do have
read access — Event Monitoring / debug logs may persist.
Recommended Workflow
- Enumerate every query / report / list view / filter that touches
each candidate field.
- Classify each query: exact, range, LIKE, aggregate, display.
- Apply the scheme matrix. Flag fields where encryption blocks a
required query.
- For blocked fields, decide: drop the requirement, skip encryption,
or derive a hashed index field (one-way).
- Request custom indexes on deterministic fields used as filters.
- 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".
- Document the scheme per field in a schema decision log.
Official Sources Used
1---2name: encrypted-field-query-patterns3description: "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."4category: security5salesforce-version: "Spring '25+"6well-architected-pillars:7 - Security8 - Performance9 - Reliability10triggers:11 - "query encrypted field"12 - "shield platform encryption filter"13 - "deterministic encryption selection"14 - "encrypted field index"15 - "encrypted field soql limitations"16tags:17 - security18 - shield19 - encryption20 - soql21inputs:22 - List of fields requiring encryption23 - Query patterns over those fields (exact, range, like, aggregate)24 - Reporting requirements25outputs:26 - Encryption scheme choice per field (probabilistic / deterministic / case-sensitive deterministic)27 - SOQL pattern guidance per field28 - Index and reporting plan29dependencies: []30version: 1.0.031author: Pranav Nagrecha32updated: 2026-04-2333metadata:34 source: https://skillmd.com/skills/pranavnagrecha/encrypted-field-query-patterns35---3637# Encrypted Field Query Patterns3839## The Core Constraint4041Shield Platform Encryption changes SOQL semantics. Plan the queries42FIRST, then choose the encryption scheme. Reversing that order means43rebuilding schemas later.4445## Scheme Matrix4647| Scheme | Use Case | SOQL Support |48|---|---|---|49| **Probabilistic** | Max security, display-only | NO filter, NO sort, NO group by, NO index |50| **Deterministic (case-sensitive)** | Exact match required | `=`, `IN`, joins, unique indexes; NO range, NO LIKE |51| **Deterministic (case-insensitive)** | Exact match, case-agnostic | `=`, `IN`; NO range, NO LIKE |5253No scheme supports `LIKE` on encrypted fields. No scheme supports range54(`>`, `<`, `BETWEEN`) operators.5556## Decision By Query Pattern5758| Query | Scheme |59|---|---|60| Display only (never filter) | Probabilistic |61| Lookup by exact value | Deterministic (case-sensitive if value is case-stable) |62| Customer search by name (case-agnostic) | Deterministic case-insensitive |63| Range query (date, amount) | **Do not encrypt** — use field-level security + masking |64| LIKE search | **Do not encrypt** — or store a derived hash/index field |65| Sort by field | Only if you rely on display order, not SOQL ORDER BY |6667## Indexing6869- Custom indexes on deterministic encrypted fields are supported for70 equality filters.71- Standard indexes (lookup, master-detail) are not automatically present72 on encrypted fields — request a custom index.73- Query selectivity degrades if the encrypted field has low cardinality74 post-encryption.7576## Aggregation And Reporting7778- GROUP BY on encrypted field: supported only with deterministic.79- SUM / AVG on an encrypted number: generally not supported — leave80 aggregatable numerics unencrypted unless compliance requires.81- Reports with filters on encrypted fields: equality works for82 deterministic; others fail at runtime.8384## Apex Patterns8586Shield Platform Encryption decrypts **transparently**. Any user with87field-level READ access on the field receives plaintext — in Apex, in88SOQL results, in reports, and in the UI. There is no separate89"show me the plaintext" permission you can withhold.9091> **Shield vs Classic — do not merge these.** The **"View Encrypted92> Data"** permission belongs to **Classic Encryption**, the legacy93> `Encrypted Text` custom field type, where a user without it sees94> `*********`. Shield Platform Encryption has not used that permission95> since Spring '17. Removing "View Encrypted Data" does **not** mask a96> Shield-encrypted field — the user still sees plaintext if FLS grants97> read. Guidance that says otherwise tells a reader data is protected98> when it is not.99100Plaintext visibility for Shield is restricted with **field-level101security** (profiles / permission sets), page layouts, and sharing.102Encryption is an at-rest control, not an authorization control. Plan for:103104- Test users with FLS read granted and FLS read removed on each105 encrypted field.106- Avoid logging encrypted values in `System.debug` even when you do have107 read access — Event Monitoring / debug logs may persist.108109## Recommended Workflow1101111. Enumerate every query / report / list view / filter that touches112 each candidate field.1132. Classify each query: exact, range, LIKE, aggregate, display.1143. Apply the scheme matrix. Flag fields where encryption blocks a115 required query.1164. For blocked fields, decide: drop the requirement, skip encryption,117 or derive a hashed index field (one-way).1185. Request custom indexes on deterministic fields used as filters.1196. Test with a user who has FLS read on the field and one who does not120 — Shield gates plaintext on FLS, not on "View Encrypted Data".1217. Document the scheme per field in a schema decision log.122123## Official Sources Used124125- Shield Platform Encryption Overview —126 https://help.salesforce.com/s/articleView?id=sf.security_pe_overview.htm127- Deterministic Encryption —128 https://help.salesforce.com/s/articleView?id=sf.security_pe_deterministic_encryption.htm129- Encrypted Fields In SOQL —130 https://help.salesforce.com/s/articleView?id=sf.security_pe_apps_soql.htm131- Use Field-Level, Event Bus, and Search Encryption (Trailhead) —132 "encryption doesn't take the place of field-level access controls" —133 https://trailhead.salesforce.com/content/learn/modules/spe_admins/spe_admins_deploy134- View Encrypted Data Permission Not Needed with Shield Platform135 Encryption Beginning Spring '17 —136 https://help.salesforce.com/s/articleView?id=000382508&type=1137- Classic Encryption for Custom Fields (the feature that DOES use138 "View Encrypted Data") —139 https://help.salesforce.com/s/articleView?id=platform.fields_about_encrypted_fields.htm&type=5