WHERE
For more details check SOQLCache Cache API - WHERE.
NOTE! 🚨 All examples use inline queries built with the SOQL Lib Query Builder. If you are using a selector, replace
SOQLCache.of(...)
withYourCachedSelectorName.query()
.
SObjectField (Recommended)​
SOQL
SELECT Id, Name, UserType
FROM Profile
WHERE Name = 'System Administrator'
SOQL Lib
SOQLCache.of(Profile.SObjectType)
.with(Profile.Id, Profile.Name, Profile.UserType)
.whereEqual(Profile.Name, 'System Administrator')
.toObject();
String​
SOQL
SELECT Id, Name, UserType
FROM Profile
WHERE Name = 'System Administrator'
SOQL Lib
SOQLCache.of(Profile.SObjectType)
.with(Profile.Id, Profile.Name, Profile.UserType)
.whereEqual('Name', 'System Administrator')
.toObject();
Cache Configuration Options​
allowFilteringByNonUniqueFields()​
By default, cached queries can only be filtered by unique fields (Id
, Name
, DeveloperName
) or fields marked as unique in the schema. This is a safety measure to ensure cache consistency. If you need to filter by non-unique fields, you can disable this validation:
SOQLCache.of(Profile.SObjectType)
.allowFilteringByNonUniqueFields()
.with(Profile.Id, Profile.Name, Profile.UserType)
.whereEqual(Profile.UserType, 'Standard')
.toObject();
Use allowFilteringByNonUniqueFields()
carefully, as non-unique fields cannot guarantee that the correct records are returned from the cache.
allowQueryWithoutConditions()​
By default, cached queries require at least one condition to prevent accidental retrieval of all cached records. You can disable this validation to allow queries without conditions:
SOQLCache.of(Profile.SObjectType)
.allowQueryWithoutConditions()
.with(Profile.Id, Profile.Name, Profile.UserType)
.toObject(); // Returns first cached record without any conditions
When using allowQueryWithoutConditions()
, the query will return the first available record from the cache if no conditions are specified.