Skip to main content

SELECT

Specify fields that will be retrieved via query. Check SOQLCache Cache API - SELECT.

NOTE! 🚨 All examples use inline queries built with the SOQL Lib Query Builder. If you are using a selector, replace SOQLCache.of(...) with YourCachedSelectorName.query().

Fields​

SOQL

Traditional SOQL
SELECT Id, Name, BillingCity
FROM Account
WHERE Id = '1234'

SOQL Lib

SOQL Cache Approach
SOQLCache.of(Account.SObjectType)
.with(Account.Id, Account.Name, Account.BillingCity)
.byId('1234')
.toObject();

More than 5 fields:

SOQL

Traditional SOQL
SELECT
Id,
Name,
Industry,
Rating,
AnnualRevenue,
BillingCity,
Phone
FROM Account
WHERE Id = '1234'

SOQL Lib

SOQL Cache Approach
SOQLCache.of(Account.SObjectType)
.with(new List<SObjectField> {
Account.Id,
Account.Name,
Account.Industry,
Account.Rating,
Account.AnnualRevenue,
Account.BillingCity,
Account.Phone
})
.byId('1234')
.toObject();

String fields​

SOQL

Traditional SOQL
SELECT Id, Name, Industry, Rating, AnnualRevenue, BillingCity, Phone
FROM Account
WHERE Id = '1234'

SOQL Lib

SOQL Cache Approach
SOQLCache.of(Account.SObjectType)
.with('Id, Name, Industry, Rating, AnnualRevenue, BillingCity, Phone')
.byId('1234')
.toObject();

Relationship Fields​

Single Relationship Field​

SOQL

Traditional SOQL
SELECT Id, Name, Owner.Name
FROM Account
WHERE Id = '1234'

SOQL Lib

SOQL Cache Approach
SOQLCache.of(Account.SObjectType)
.with(Account.Id, Account.Name)
.with('Owner', User.Name)
.byId('1234')
.toObject();

Multiple Relationship Fields​

SOQL

Traditional SOQL
SELECT Id, Name, Owner.Name, Owner.Email, CreatedBy.Name
FROM Account
WHERE Id = '1234'

SOQL Lib

SOQL Cache Approach
SOQLCache.of(Account.SObjectType)
.with(Account.Id, Account.Name)
.with('Owner', User.Name, User.Email)
.with('CreatedBy', User.Name)
.byId('1234')
.toObject();

Relationship Fields with List​

SOQL

Traditional SOQL
SELECT Id, Name, Owner.Name, Owner.Email, Owner.Profile.Name
FROM Account
WHERE Id = '1234'

SOQL Lib

SOQL Cache Approach
SOQLCache.of(Account.SObjectType)
.with(Account.Id, Account.Name)
.with('Owner', new List<SObjectField>{ User.Name, User.Email })
.with('Owner.Profile', Profile.Name)
.byId('1234')
.toObject();