Apex BOOST Library
v1.7 from Lucidware Solutions (LWS)

Query

global inherited sharing class Query
DescriptionUsing this class, a dynamic query can be constructed piece by piece, adding object and field type checking, which avoids typos and references to invalid fields.

By default, 'WITH USER_MODE' will be added when executing the query. If any fields or objects referenced in the query are inaccessible to the user, a QueryException is thrown. This can be disabled, if desired.

Usage:
 // get user names where City starts with "San" (method chaining)
 User[] users = new aBoost.Query(User.SObjectType)
   .field(User.Name)
   .whereOp(User.City, 'LIKE', 'San%')
   .run();

 // get the number of contacts in Dallas accounts (complex query)
 aBoost.Query dallasAccounts = new aBoost.Query(Account.SObjectType)
   .whereOp(Account.City, '=', 'Dallas'));
 Integer contactCount = new aBoost.Query(Contact.SObjectType)
   .field(Contact.Name)
   .whereIn(Contact.AccountId, dallasAccounts)
   .count();

 // get the contacts in certain accounts (child query)
 Account[] results = new aBoost.Query(Account.SObjectType)
   .fields(new Query().createChildQuery(Contact.SObjectType, 'Contacts'))
   .whereIn(Account.Id, accounts)
   .run();
 

Constructors

  Query

global Query(SObjectType objectType)
DescriptionCreate a query for the specified SObjectType
ThrowsInvalidParameterValueException if objectType is null

  Query

global Query()
DescriptionConstruct a query with no object name. This can be useful in constructing a WHERE clause

Methods

  count

global Integer count()
DescriptionExecutes a "count" query (i.e. Database.countQuery())

  createChildQuery

global static Query createChildQuery(SObjectType objectType, String objectName)
DescriptionCreate a child query for the specified SObjectType and relationship name. The resulting object can then be passed to a field() call.
ThrowsInvalidParameterValueException if objectType is null, or objectName is blank

  field

global Query field(SObjectField field)
DescriptionAdd the specified field to the SELECT list
ThrowsInvalidParameterValueException if field is null

  field

global Query field(String field)
DescriptionAdd the specified field to the SELECT list
ThrowsInvalidParameterValueException if field is blank

  fields

global Query fields(SObjectField[] fields)
DescriptionAdd the specified fields to the SELECT list
ThrowsInvalidParameterValueException if fields is null or empty

  fields

global Query fields(String[] fields)
DescriptionAdd the specified fields to the SELECT list
ThrowsInvalidParameterValueException if fields is null or empty

  fields

global Query fields(Set<SObjectField> fields)
DescriptionAdd the specified fields to the SELECT list
ThrowsInvalidParameterValueException if fields is null or empty

  fields

global Query fields(Set<String> fields)
DescriptionAdd the specified fields to the SELECT list
ThrowsInvalidParameterValueException if fields is null or empty

  fields

global Query fields(Query childQuery)
DescriptionAdd the specified child query to the SELECT list
ThrowsInvalidParameterValueException if childQuery is not a valid child query

  fields

global Query fields(FieldSetMember[] members)
DescriptionAdd the specified field set members to the SELECT list
ThrowsInvalidParameterValueException if members is null

  groupBy

global Query groupBy(SObjectField field)
DescriptionSpecify a GROUP BY field
ThrowsInvalidParameterValueException if field is null

  groupBy

global Query groupBy(SObjectField[] fields)
DescriptionSpecify GROUP BY fields
ThrowsInvalidParameterValueException if fields is null or empty

  groupBy

global Query groupBy(String field)
DescriptionSpecify a GROUP BY clause
ThrowsInvalidParameterValueException if clause is null

  groupBy

global Query groupBy(String[] fields)
DescriptionSpecify GROUP BY fields
ThrowsInvalidParameterValueException if fields is null or empty

  locator

global Database.QueryLocator locator()
Returnsa Database.QueryLocator; useful in a Batchable.start method

  orderBy

global Query orderBy(SObjectField field)
DescriptionSpecify an ORDER BY field
ThrowsInvalidParameterValueException if field is null

  orderBy

global Query orderBy(String field)
DescriptionSpecify an ORDER BY field
ThrowsInvalidParameterValueException if field is empty

  orderBy

global Query orderBy(String[] fields)
DescriptionSpecify ORDER BY fields
ThrowsInvalidParameterValueException if fields is null or empty

  orderBy

global Query orderBy(Set<String> fields)
DescriptionSpecify ORDER BY fields
ThrowsInvalidParameterValueException if fields is null or empty

  orderBy

global Query orderBy(SObjectField field, Boolean sortAsc)
DescriptionSpecify an ORDER BY field
ThrowsInvalidParameterValueException if field is null

  orderBy

global Query orderBy(String field, Boolean sortAsc)
DescriptionSpecify an ORDER BY field
ThrowsInvalidParameterValueException if field is empty

  orderBy

global Query orderBy(SObjectField field, Boolean sortAsc, Boolean nullsFirst)
DescriptionSpecify an ORDER BY field
ThrowsInvalidParameterValueException if field is null

  orderBy

global Query orderBy(String field, Boolean sortAsc, Boolean nullsFirst)
DescriptionSpecify an ORDER BY field
ThrowsInvalidParameterValueException if field is empty

  run

global SObject[] run()
DescriptionExecutes the query (i.e. Database.query())

  setEnforceSecurity

global Query setEnforceSecurity(Boolean enforceSecurity)
DescriptionSet the enforceSecurity attribute. If true, 'WITH USER_MODE' will be added to the query. By default, enforceSecurity is true.

  setLimit

global Query setLimit(Integer theLimit)
ThrowsInvalidParameterValueException if theLimit is null or negative

  setOffset

global Query setOffset(Integer theOffset)
ThrowsInvalidParameterValueException if offset is null or negative

  toString

global override String toString()
DescriptionStandard toString override

  whereAnd

global Query whereAnd(Query query)
DescriptionSpecify an AND clause that will be grouped within parenthesis. Use an empty constructor to build the query to be passed in.
ThrowsInvalidParameterValueException if query is null

  whereIn

global Query whereIn(SObjectField field, Object[] values)
DescriptionAdd a WHERE clause (field IN values)
ThrowsInvalidParameterValueException if field is null, or values is null or empty

  whereIn

global Query whereIn(SObjectField field, SObject[] values)
DescriptionAdd a WHERE clause (field IN values)
ThrowsInvalidParameterValueException if field is null, or values is null or empty

  whereIn

global Query whereIn(SObjectField field, Set<Object> values)
DescriptionAdd a WHERE clause (field IN values)
ThrowsInvalidParameterValueException if field is null, or values is null or empty

  whereIn

global Query whereIn(SObjectField field, Set<Id> ids)
DescriptionAdd a WHERE clause (field IN values)
ThrowsInvalidParameterValueException if field is null, or values is null or empty

  whereIn

global Query whereIn(SObjectField field, Query query)
DescriptionAdd a WHERE clause (field IN query)
ThrowsInvalidParameterValueException if field is null, or query is null

  whereIn

global Query whereIn(String field, Object[] values)
DescriptionAdd a WHERE clause (field IN values)
ThrowsInvalidParameterValueException if field is null, or values is null or empty

  whereIn

global Query whereIn(String field, SObject[] values)
DescriptionAdd a WHERE clause (field IN values)
ThrowsInvalidParameterValueException if field is null, or values is null or empty

  whereIn

global Query whereIn(String field, Set<Object> values)
DescriptionAdd a WHERE clause (field IN values)
ThrowsInvalidParameterValueException if field is null, or values is null or empty

  whereIn

global Query whereIn(String field, Set<Id> values)
DescriptionAdd a WHERE clause (field IN values)
ThrowsInvalidParameterValueException if field is null, values is null or empty

  whereIn

global Query whereIn(String field, Query query)
DescriptionAdd a WHERE clause (field IN query)
ThrowsInvalidParameterValueException if field is null, or query is null

  whereNotIn

global Query whereNotIn(SObjectField field, Object[] values)
DescriptionAdd a WHERE clause (field NOT IN values)
ThrowsInvalidParameterValueException if field is null, or values is null or empty

  whereNotIn

global Query whereNotIn(SObjectField field, SObject[] values)
DescriptionAdd a WHERE clause (field NOT IN values)
ThrowsInvalidParameterValueException if field is null, or values is null or empty

  whereNotIn

global Query whereNotIn(SObjectField field, Set<Object> values)
DescriptionAdd a WHERE clause (field NOT IN values)
ThrowsInvalidParameterValueException if field is null, or values is null or empty

  whereNotIn

global Query whereNotIn(SObjectField field, Set<Id> values)
DescriptionAdd a WHERE clause (field NOT IN values)
ThrowsInvalidParameterValueException if field is null, or values is null or empty

  whereNotIn

global Query whereNotIn(SObjectField field, Query query)
DescriptionAdd a WHERE clause (field NOT IN values)
ThrowsInvalidParameterValueException if field is null, or query is null

  whereNotIn

global Query whereNotIn(String field, Object[] values)
DescriptionAdd a WHERE clause (field NOT IN values)
ThrowsInvalidParameterValueException if field is null, or values is null or empty

  whereNotIn

global Query whereNotIn(String field, SObject[] values)
DescriptionAdd a WHERE clause (field NOT IN values)
ThrowsInvalidParameterValueException if field is null, or values is null or empty

  whereNotIn

global Query whereNotIn(String field, Set<Object> values)
DescriptionAdd a WHERE clause (field NOT IN values)
ThrowsInvalidParameterValueException if field is null, or values is null or empty

  whereNotIn

global Query whereNotIn(String field, Set<Id> values)
DescriptionAdd a WHERE clause (field NOT IN values)
ThrowsInvalidParameterValueException if field is null, or values is null or empty

  whereNotIn

global Query whereNotIn(String field, Query query)
DescriptionAdd a WHERE clause (field NOT IN query)
ThrowsInvalidParameterValueException if field is null, or query is null

  whereOp

global Query whereOp(SObjectField field, String op, Object value)
DescriptionAdd a WHERE clause (field value)
ThrowsInvalidParameterValueException if field is null, or op is invalid (valid operators are =, !=, <, <=, >, >=, LIKE)

  whereOp

global Query whereOp(String field, String op, Object value)
DescriptionAdd a WHERE clause (field value)
ThrowsInvalidParameterValueException if field is null, or op is invalid (valid operators are =, !=, <, <=, >, >=, LIKE)

  whereOp

global Query whereOp(String clause)
DescriptionAdd a free-form WHERE clause
ThrowsInvalidParameterValueException if clause is empty

  whereOr

global Query whereOr(Query query)
DescriptionSpecify an OR clause that will be grouped within parenthesis. Use an empty constructor to build the query to be passed in.
ThrowsInvalidParameterValueException if query is null