You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Subsequent call: retrieves from cache, no database query
163
160
return SOQL_CachedProfile.query()
164
161
.byName('Standard User')
@@ -169,7 +166,7 @@ public with sharing class ExampleController {
169
166
170
167
## Field-Level Security
171
168
172
-
Unlike standard SOQL queries that use `WITH USER_MODE`, cached records require the `Security.stripInaccessible` method to enforce field-level security. This method works with both fresh query results and cached records.
169
+
Unlike standard SOQL queries that use `WITH USER_MODE` all cached queries are executed `WITH SYSTEM_MODE`. To apply FLY to the cached records the `.stripInaccessible()` has to me invoked.
173
170
174
171
### stripInaccessible
175
172
@@ -249,6 +246,8 @@ SOQLCache supports mocking for unit tests. You can mock either the cached result
249
246
250
247
### Mock Cached Results
251
248
249
+
To learn more about mocking in the cache module check the [Mocking](./examples/mocking.md) section.
250
+
252
251
```apex title="ExampleController.cls"
253
252
public with sharing class ExampleController {
254
253
public static Profile getSystemAdminProfile() {
@@ -401,7 +400,7 @@ SObject toObject() // Get single record
401
400
402
401
### Extract Record ID from Cache
403
402
404
-
❌ **Traditional approach:**
403
+
❌
405
404
406
405
```apex title="Traditional SOQL"
407
406
public static Id getSystemAdminProfileId() {
@@ -415,7 +414,7 @@ public static Id getSystemAdminProfileId() {
415
414
}
416
415
```
417
416
418
-
✅ **With SOQLCache:**
417
+
✅
419
418
420
419
```apex title="With SOQLCache"
421
420
public static Id getSystemAdminProfileId() {
@@ -427,7 +426,7 @@ public static Id getSystemAdminProfileId() {
427
426
428
427
### Extract Field Value from Cache
429
428
430
-
❌ **Traditional approach:**
429
+
❌
431
430
432
431
```apex title="Traditional SOQL"
433
432
public static String getSystemAdminUserType() {
@@ -441,7 +440,7 @@ public static String getSystemAdminUserType() {
441
440
}
442
441
```
443
442
444
-
✅ **With SOQLCache:**
443
+
✅
445
444
446
445
```apex title="With SOQLCache"
447
446
public static String getSystemAdminUserType() {
@@ -453,7 +452,7 @@ public static String getSystemAdminUserType() {
453
452
454
453
### Check Record Existence in Cache
455
454
456
-
❌**Traditional approach:**
455
+
❌
457
456
458
457
```apex title="Traditional SOQL"
459
458
public static Boolean hasStandardUserProfile() {
@@ -467,7 +466,7 @@ public static Boolean hasStandardUserProfile() {
In this configuration, you can specify default fields, the cache storage type `cacheIn...` (Org Cache, Session Cache, or Apex transaction), and the time in hours before a refresh is required (`maxHoursWithoutRefresh`). Additionally, you can add an `initialQuery()` to prepopulate records in the cache, ensuring that subsequent queries retrieve records from the prepopulated set.
15
+
In this configuration, you can specify default fields, the cache storage type `cacheIn...` (Org Cache, Session Cache, or Apex transaction), and the time in hours before a refresh is required (`maxHoursWithoutRefresh`). Additionally, you can add an `initialQuery()` to prepopulate records in the cache, ensuring that subsequent queries retrieve records from the prepopulated set. The `additionalAllowedConditionFields` allows you to specify which additional fields can be used in conditions besides `Id, Name, DeveloperName` and unique fields. You change it at your own risk, because non-unique fields cannot guarantee that the correct records are returned from the cache. More details [here](./advanced/design#cached-query-required-single-condition).
16
16
17
17
```apex
18
18
public with sharing class SOQL_ProfileCache extends SOQLCache implements SOQLCache.Selector {
@@ -31,6 +31,12 @@ public with sharing class SOQL_ProfileCache extends SOQLCache implements SOQLCac
31
31
return SOQL.of(Profile.SObjectType);
32
32
}
33
33
34
+
public override List<SObjectField> additionalAllowedConditionFields() {
0 commit comments