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
Encrypted fields read and write transparently in Apex for users with
"View Encrypted Data" permission. Without that permission, reads return
masked values (*********). Plan for:
- Test users with both modes.
- Avoid logging encrypted values in
System.debug even when you have
permission — 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 both "View Encrypted Data" and masked users.
- Document the scheme per field in a schema decision log.
Official Sources Used
1---
2name: encrypted-field-query-patterns
3description: "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, encrypted field index. Does NOT cover: Classic Encryption (deprecated), field-level security policy, or tenant secret key rotation."
4category: security
5salesforce-version: "Spring '25+"
6well-architected-pillars:
7 - Security
8 - Performance
9 - Reliability
10triggers:
11 - "query encrypted field"
12 - "shield platform encryption filter"
13 - "deterministic encryption selection"
14 - "encrypted field index"
15 - "encrypted field soql limitations"
16tags:
17 - security
18 - shield
19 - encryption
20 - soql
21inputs:
22 - List of fields requiring encryption
23 - Query patterns over those fields (exact, range, like, aggregate)
24 - Reporting requirements
25outputs:
26 - Encryption scheme choice per field (probabilistic / deterministic / case-sensitive deterministic)
27 - SOQL pattern guidance per field
28 - Index and reporting plan
29dependencies: []
30version: 1.0.0
31author: Pranav Nagrecha
32updated: 2026-04-23
33metadata:
34 source: https://skillmd.com/skills/aibot88/encrypted-field-query-patterns
35---
36
37# Encrypted Field Query Patterns
38
39## The Core Constraint
40
41Shield Platform Encryption changes SOQL semantics. Plan the queries
42FIRST, then choose the encryption scheme. Reversing that order means
43rebuilding schemas later.
44
45## Scheme Matrix
46
47| 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 |
52
53No scheme supports `LIKE` on encrypted fields. No scheme supports range
54(`>`, `<`, `BETWEEN`) operators.
55
56## Decision By Query Pattern
57
58| 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 |
66
67## Indexing
68
69- Custom indexes on deterministic encrypted fields are supported for
70 equality filters.
71- Standard indexes (lookup, master-detail) are not automatically present
72 on encrypted fields — request a custom index.
73- Query selectivity degrades if the encrypted field has low cardinality
74 post-encryption.
75
76## Aggregation And Reporting
77
78- GROUP BY on encrypted field: supported only with deterministic.
79- SUM / AVG on an encrypted number: generally not supported — leave
80 aggregatable numerics unencrypted unless compliance requires.
81- Reports with filters on encrypted fields: equality works for
82 deterministic; others fail at runtime.
83
84## Apex Patterns
85
86Encrypted fields read and write transparently in Apex for users with
87"View Encrypted Data" permission. Without that permission, reads return
88masked values (`*********`). Plan for:
89
90- Test users with both modes.
91- Avoid logging encrypted values in `System.debug` even when you have
92 permission — Event Monitoring / debug logs may persist.
93
94## Recommended Workflow
95
961. Enumerate every query / report / list view / filter that touches
97 each candidate field.
982. Classify each query: exact, range, LIKE, aggregate, display.
993. Apply the scheme matrix. Flag fields where encryption blocks a
100 required query.
1014. For blocked fields, decide: drop the requirement, skip encryption,
102 or derive a hashed index field (one-way).
1035. Request custom indexes on deterministic fields used as filters.
1046. Test with both "View Encrypted Data" and masked users.
1057. Document the scheme per field in a schema decision log.
106
107## Official Sources Used
108
109- Shield Platform Encryption Overview —
110 https://help.salesforce.com/s/articleView?id=sf.security_pe_overview.htm
111- Deterministic Encryption —
112 https://help.salesforce.com/s/articleView?id=sf.security_pe_deterministic_encryption.htm
113- Encrypted Fields In SOQL —
114 https://help.salesforce.com/s/articleView?id=sf.security_pe_apps_soql.htm