QS
of
Conctructs an QS
.
Signature
static QS of(sObjectType ofObject)
Example
QS.of(Account.sObjectType)
QS.of(Contact.sObjectType)
fields
SELECT
statement that specifies the fields to query. The fieldList in theSELECT
statement specifies the list of one or more fields, separated by commas, that you want to retrieve.
Signature
QS fields(List<sObjectField> fields)
Example
QS.of(Account.sObjectType).fields(List<sObjectField>{
Account.Id,
Account.Name,
Account.Industry
})
QS.of(Contact.sObjectType).fields(List<sObjectField>{
Contact.Id,
Contact.FirstName,
Contact.LastName
})
relatedFields
Allows to add parent field to a query.
Signature
QS relatedFields(String relationshipPath, List<sObjectField> fields)
Example
QS.of(Account.sObjectType).relatedFields('CreatedBy', List<sObjectField>{
User.Id,
User.Name
})
QS.of(Contact.sObjectType).relatedFields('Account', List<sObjectField>{
Account.Id,
Account.Name
})
count
COUNT()
returns the number of rows that match the filtering conditions.
Signature
QS count()
Example
QS.of(Account.sObjectType).count().asInteger()
countAs
COUNT(fieldName)
returns the number of rows that match the filtering conditions and have a non-null value for fieldName.
Signature
countAs(sObjectField field, String alias)
Example
QS_Account.Selector.countAs(Account.Name, 'names').asAggregated()
subQuery
Use SOQL to query several relationship types.
For more details check QB.Sub
class.
Signature
QS subQuery(QB_Sub subQuery)
Example
QS.of(Account.sObjectType)
.subQuery(QS.Sub.of('Contacts')
.fields(new List<sObjectField>{
Contact.Id,
Contact.Name
})
)
scope
delegatedScope
Filter for records delegated to another user for action. For example, a query could filter for only delegated Task records.
Signature
QS delegatedScope()
Example
QS.of(Task.sObjectType).delegatedScope()
mineScope
Filter for records owned by the user running the query.
Signature
QS mineScope()
Example
QS.of(Account.sObjectType).mineScope()
mineAndMyGroupsScope
Filter for records assigned to the user running the query and the user’s queues. If a user is assigned to a queue, the user can access records in the queue. This filter applies only to the ProcessInstanceWorkItem object.
Signature
QS mineAndMyGroupsScope()
Example
QS.of(ProcessInstanceWorkItem.sObjectType).mineAndMyGroupsScope()
myTerritoryScope
Filter for records in the territory of the user running the query. This option is available if territory management is enabled for your organization.
Signature
QS myTerritoryScope()
Example
myTeamTerritoryScope
Filter for records in the territory of the team of the user running the query. This option is available if territory management is enabled for your organization.
Signature
QS myTeamTerritoryScope()
Example
teamScope
Filter for records assigned to a team, such as an Account team.
Signature
QS teamScope()
Example
QS.of(Account.sObjectType).teamScope()
whereAre
The condition expression in a
WHERE
clause of a SOQL query includes one or more field expressions. You can specify multiple field expressions in a condition expression by using logical operators.
For more details check QB.ConditionsGroup
and QB.Condition
Signature
QS whereAre(QB_ConditionClause conditions)
Example
QS.of(Account.sObjectType)
.whereAre(QS.ConditionsGroup
.add(QS.Condition.field(Account.Id).equal(accountId))
.add(QS.Condition.field(Account.Name).likeAnyBoth(accountName))
.order('1 OR 2')
)
group by
groupBy
You can use the
GROUP BY
option in a SOQL query to avoid iterating through individual query results. That is, you specify a group of records instead of processing many individual records.
Signature
QS groupBy(sObjectField field)
Example
QS.of(Lead.sObjectType)
.fields(new List<sObjectField>{
Lead.LeadSource
})
.groupBy(Lead.LeadSource)
.asAggregated();
groupByRollup
Signature
QS groupByRollup(sObjectField field)
Example
groupByCube
Signature
QS groupByCube(sObjectField field)
Example
order by
orderBy
Use the optional
ORDER BY
in aSELECT
statement of a SOQL query to control the order of the query results.
Signature
QS orderBy(sObjectField field)
Example
QS.of(Account.sObjectType).orderBy(Account.Name)
orderByRelated
Order SOQL query by parent field.
Signature
QS orderByRelated(String path, sObjectField field)
Example
QS.of(Contact.sObjectType).orderByRelated('Account', Account.Name)
sortDesc
Default order is ascending (ASC
).
Signature
QS sortDesc()
Example
QS.of(Account.sObjectType).orderBy(Account.Name).sortDesc()
nullsLast
By default, null values are sorted first (NULLS FIRST
).
Signature
QS nullsLast()
Example
QS.of(Account.sObjectType).orderBy(Account.Industry).nullsLast()
setLimit
LIMIT
is an optional clause that can be added to aSELECT
statement of a SOQL query to specify the maximum number of rows to return.
Signature
QS setLimit(Integer amount)
Example
QS.of(Account.sObjectType).setLimit(100)
setOffset
When expecting many records in a query’s results, you can display the results in multiple pages by using the
OFFSET
clause on a SOQL query.
Signature
QS setOffset(Integer startingRow)
Example
QS.of(Account.sObjectType).setOffset(10)
for
forReference
Use to notify Salesforce when a record is referenced from a custom interface, such as in a mobile application or from a custom page.
Signature
QS forReference()
Example
QS.of(Contact.sObjectType).forReference()
forView
Use to update objects with information about when they were last viewed.
Signature
QS forView()
Example
QS.of(Contact.sObjectType).forView()
forUpdate
Use to lock sObject records while they’re being updated in order to prevent race conditions and other thread safety problems.
Signature
QS forUpdate()
Example
QS.of(Contact.sObjectType).forUpdate()
allRows
Signature
QS allRows()
Example
fls
By default AccessLevel is set as USER_MODE
.
systemMode
Execution mode in which the the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords.
Signature
QS systemMode()
Example
QS.of(Account.sObjectType).systemMode()
QS.of(Contact.sObjectType).userMode()
sharing
Using the with sharing, without sharing, and inherited sharing Keywords
withSharing
Execute query with sharing
Signature
QS withSharing()
Example
QS.of(Account.sObjectType).withSharing()
QS.of(Contact.sObjectType).withSharing()
withoutSharing
Execute query without sharing
Signature
QS withoutSharing()
Example
QS.of(Account.sObjectType).withoutSharing()
QS.of(Contact.sObjectType).withoutSharing()
mocking
Signature
QS mocking(String queryIdentifier)
Example
preview
Signature
QS preview()
Example
QS.of(Account.sObjectType).preview()
QS.of(Contact.sObjectType).preview()
Query preview will be available in debug logs:
============ Query Preview ============
SELECT Name, AccountNumber, BillingCity, BillingCountry, BillingCountryCode
FROM Account
WHERE ((Id = :v1 OR Name LIKE :v2))
=======================================
============ Query Binding ============
{
"v2" : "%Test%",
"v1" : "0013V00000WNCw4QAH"
}
=======================================
result
asObject
Signature
sObject asObject()
Example
asList
Signature
List<sObject> asList()
Example
asAggregated
Signature
List<AggregateResult> asAggregated()
Example
asInteger
Signature
Integer asInteger()
Example