-
Notifications
You must be signed in to change notification settings - Fork 0
The Soql.Builder Class
This class is used to build query objects. It serves as the foundation for outer Soql queries, as well as other "query-like" objects: Soql.InnerQuery and Soql.Subquery.
--
Adds binding variables to the query. Binding variables are used to dynamically insert values into the query.
Soql.Builder addBind(Map<String, Object> bindMap)Soql.Builder addBind(String key, Object value)Soql.Builder addBind(Soql.Binder binder)
Adds fields to the GROUP BY clause of the query.
Soql.Builder addGroupBy(String fieldName)Soql.Builder addGroupBy(SObjectField field)Soql.Builder addGroupBy(Soql.ParentField field)
Adds conditions to the HAVING clause of the query.
Soql.Builder addHaving(Soql.Aggregation agg, Soql.Operator operator, Object value)
Adds fields or Soql.Selectable objects to the SELECT clause of the query. Soql.Selectable types include Soql.Aggregation, Soql.ParentField, and Soql.Subquery objects.
Soql.Builder addSelect(String fieldName, String alias)Soql.Builder addSelect(SObjectField field, String alias)Soql.Builder addSelect(Soql.ParentField field, String alias)Soql.Builder addSelect(String fieldName)Soql.Builder addSelect(List<SObjectField> fields)Soql.Builder addSelect(SObjectField field1, [field2, field3, field4, field5])Soql.Builder addSelect(List<Soql.Selectable> selectables)Soql.Builder addSelect(Soql.Selectable selectable1, [selectable2, selectable3, selectable4, selectable5])
Adds conditions to the WHERE clause of the query.
Soql.Builder addWhere(Soql.Criteria criteria)Soql.Builder addWhere(String fieldName, Soql.Operator operator, Object value)Soql.Builder addWhere(SObjectField field, Soql.Operator operator, Object value)Soql.Builder addWhere(Soql.ParentField field, Soql.Operator operator, Object value)Soql.Builder addWhere(String fieldName, Soql.Operator operator, Soql.Binder binder)Soql.Builder addWhere(SObjectField field, Soql.Operator operator, Soql.Binder binder)Soql.Builder addWhere(Soql.ParentField field, Soql.Operator operator, Soql.Binder binder)
Removes specific fields from the SELECT clause of the query.
Soql.Builder deselect(String fieldName)Soql.Builder deselect(SObjectField field)Soql.Builder deselect(Soql.ParentField field)
Removes all fields from the SELECT clause of the query, essentially clearing any previously selected fields.
Soql.Builder deselectAll()
Adds fields to the ORDER BY clause of the query.
Soql.Builder addOderBy(Soql.SortOrder sortOrder)Soql.Builder addOderBy(String fieldName, Soql.SortDirection direction)Soql.Builder addOderBy(SObjectField field, Soql.SortDirection direction)Soql.Builder addOderBy(Soql.ParentField field, Soql.SortDirection direction)
Resets the builder to its default state, clearing all previously set clauses and parameters.
Soql.Builder reset()
Selects all fields from the specified entity by querying the schema for all available fields.
Soql.Builder selectAll()
Sets the access level for the query.
Soql.Builder setAccessLevel(System.AccessLevel accessLevel)
Sets the entity from which to query data. Only call this method if you need to override the SObjectType set when constructing the query, via the DatabaseLayer.Soql.newQuery(SObjectType objectType) method.
Soql.Builder setFrom(SObjectType objectType)
Sets the logical operator (AND/OR) for combining HAVING conditions.
Soql.Builder setOuterHavingLogic(Soql.LogicType newLogicType)
Sets the logical operator (AND/OR) for combining WHERE conditions.
Soql.Builder setOuterWhereLogic(Soql.LogicType newLogicType)
Assigns an identifier to the query. Callers can use this identifier to distinguish queries from one another, for example in mocks.
Soql setQueryIdentifier(String identifier)
// In MyClass.cls:
Soql myQuery = DatabaseLayer.Soql
?.newQuery(Account.SObjectType)
?.setQueryIdentifier('My Account Query')
?.toSoql();
// In MyClassTest.cls:
MockSoql.Simulator queryMock = new MyQueryMock();
DatabaseLayer.useMocks().setGlobalMock(queryMock);
private class MyQueryMock implements MockSoql.Simulator {
public List<Object> simulateQuery(Soql queryToMock) {
if (queryToMock?.identifier == 'My Account Query') {
// Do some mocking logic specific to this query
} else {
// Do some other mocking logic for other queries...
}
}
}Sets the maximum number of rows to return in the query result.
Soql.Builder setRowLimit(Integer rowLimit)
Sets the number of rows to skip before starting to return results.
Soql.Builder setRowOffset(Integer rowOffset)
Sets the scope for the query.
Soql.Builder setScope(Soql.Scope scope)
Sets the usage context for the query.
Soql.Builder setUsage(Soql.Usage usage)
Explicitly casts the current Soql.Builder to a Soql.InnerQuery instance. Useful for chaining complex queries.
Soql.InnerQuery toInnerQuery()
Explicitly casts the current Soql.Builder to a Soql instance. Useful for chaining complex queries.
Soql toSoql()
Explicitly casts the current Soql.Builder to a Soql.Subquery instance. Useful for chaining complex queries.
Soql.Subquery toSubquery()
Enforces security in the query to ensure that the user has appropriate access to the queried records.
Soql.Builder withSecurityEnforced()
- Generating Test Records
- Dml
- Soql
- Cmdt
- Plugins
- DatabaseLayer
- Dml
- MockDml
- MockRecord
- Cmdt
- MockCmdt
- MockSoql
-
Soql
- Soql.AggregateResult
- Soql.Aggregation
- Soql.Binder
- Soql.Builder
- Soql.Condition
- Soql.ConditionalLogic
- Soql.Criteria
- Soql.Cursor
- Soql.Function
- Soql.InnerQuery
- Soql.InvalidParameterValueException
- Soql.LogicType
- Soql.NullOrder
- Soql.Operation
- Soql.Operator
- Soql.ParentField
- Soql.PreAndPostProcessor
- Soql.QueryLocator
- Soql.Request
- Soql.Scope
- Soql.Selectable
- Soql.SortDirection
- Soql.SortOrder
- Soql.Subquery
- Soql.TypeOf
- Soql.Usage
- Soql.WhenClause