Skip to content

QRY_Builder.ConditionBuilder ​

Class · Group: Query Infrastructure

Learn it: Fast Start - Selectors and Selectors guide

apex
global inherited sharing class QRY_Builder.ConditionBuilder

Fluent builder for field-level conditions (WHERE and HAVING).


Methods by task ​

Find a method by what you want to do. A group links to a worked example when a guide has one. Every method is described in the full list below.

GroupMethodsWorked example
Compare with one valueequals greaterThan greaterThanOrEquals isNotNull isNull lessThan lessThanOrEquals notEqualsQuery with Single Condition
Match a list of values, or the results of another queryisIn isInStrict notIn notInSet notInSetStrictUsing IN Operator with Collection, Semi-Join Subqueries
Match part of a textcontains endsWith startsWithString Pattern Matching, Searching for text a person typed
Filter a multi-select picklistexcludes excludesStrict includes includesStrictMulti-Picklist Field Filtering

Methods ​

MethodDescription
global QRY_Builder.Builder contains(String value)Adds a LIKE condition with wildcards on both sides (contains).
global QRY_Builder.Builder endsWith(String value)Adds a LIKE condition with wildcard at start (ends with).
global QRY_Builder.Builder equals(Object value)Keeps the records whose field holds exactly this value.
global QRY_Builder.Builder equals(SObject record)Adds an = condition comparing to an SObject's Id.
global QRY_Builder.Builder excludes(List<Object> values)Adds an EXCLUDES condition for multi-picklist fields.
global QRY_Builder.Builder excludes(Set<Object> values)Adds an EXCLUDES condition for multi-picklist fields using a Set.
global QRY_Builder.Builder excludesStrict(List<Object> values)Adds an EXCLUDES condition with strict empty list handling.
global QRY_Builder.Builder excludesStrict(Set<Object> values)Adds an EXCLUDES condition with strict empty set handling.
global QRY_Builder.Builder greaterThan(Object value)Keeps the records whose field is larger than this value; for a date or a time, later.
global QRY_Builder.Builder greaterThanOrEquals(Object value)Keeps the records whose field is equal to this value or larger; for a date or a time, the same or later.
global QRY_Builder.Builder includes(List<Object> values)Adds an INCLUDES condition for multi-picklist fields.
global QRY_Builder.Builder includes(Set<Object> values)Adds an INCLUDES condition for multi-picklist fields using a Set.
global QRY_Builder.Builder includesStrict(List<Object> values)Adds an INCLUDES condition with strict empty list handling.
global QRY_Builder.Builder includesStrict(Set<Object> values)Adds an INCLUDES condition with strict empty set handling.
global QRY_Builder.Builder isIn(List<Object> values)Adds an IN condition using a List.
global QRY_Builder.Builder isIn(List<SObject> records)Adds an IN condition using a List of SObjects.
global QRY_Builder.Builder isIn(List<SObject> records, SObjectField field)Adds an IN condition by extracting field values from SObjects.
global QRY_Builder.Builder isIn(QRY_Builder.Builder subquery)Adds a semi-join IN condition using a subquery.
global QRY_Builder.Builder isIn(Set<Object> values)Keeps the records whose field holds any one of these values.
global QRY_Builder.Builder isInStrict(List<Object> values)Adds an IN condition with strict empty list handling.
global QRY_Builder.Builder isInStrict(List<SObject> records)Adds an IN condition using SObjects with strict handling.
global QRY_Builder.Builder isInStrict(List<SObject> records, SObjectField field)Adds an IN condition by extracting field values with strict handling.
global QRY_Builder.Builder isInStrict(Set<Object> values)Adds an IN condition with strict empty set handling.
global QRY_Builder.Builder isNotNull()Keeps the records whose field has a value.
global QRY_Builder.Builder isNull()Keeps the records whose field is blank.
global QRY_Builder.Builder lessThan(Object value)Keeps the records whose field is smaller than this value; for a date or a time, earlier.
global QRY_Builder.Builder lessThanOrEquals(Object value)Keeps the records whose field is equal to this value or smaller; for a date or a time, the same or earlier.
global QRY_Builder.Builder notEquals(Object value)Leaves out the records whose field holds exactly this value.
global QRY_Builder.Builder notEquals(SObject record)Adds a != condition comparing to an SObject's Id.
global QRY_Builder.Builder notIn(QRY_Builder.Builder subquery)Adds an anti-join NOT IN condition using a subquery.
global QRY_Builder.Builder notInSet(List<Object> values)Adds a NOT IN condition using a List.
global QRY_Builder.Builder notInSet(List<SObject> records)Adds a NOT IN condition using a List of SObjects.
global QRY_Builder.Builder notInSet(List<SObject> records, SObjectField field)Adds a NOT IN condition by extracting field values from SObjects.
global QRY_Builder.Builder notInSet(Set<Object> values)Leaves out the records whose field holds any one of these values.
global QRY_Builder.Builder notInSetStrict(List<Object> values)Adds a NOT IN condition with strict empty list handling.
global QRY_Builder.Builder notInSetStrict(List<SObject> records)Adds a NOT IN condition using SObjects with strict handling.
global QRY_Builder.Builder notInSetStrict(List<SObject> records, SObjectField field)Adds a NOT IN condition by extracting field values with strict handling.
global QRY_Builder.Builder notInSetStrict(Set<Object> values)Adds a NOT IN condition with strict empty set handling.
global QRY_Builder.Builder startsWith(String value)Adds a LIKE condition with wildcard at end (starts with).

contains ​

apex
global QRY_Builder.Builder contains(String value)

Adds a LIKE condition with wildcards on both sides (contains).

Parameters

ParameterTypeDescription
valueStringText to search for

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Name).contains('Corp')
    .toList();

endsWith ​

apex
global QRY_Builder.Builder endsWith(String value)

Adds a LIKE condition with wildcard at start (ends with).

Parameters

ParameterTypeDescription
valueStringText suffix

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Name).endsWith('Inc.')
    .toList();

equals ​

apex
global QRY_Builder.Builder equals(Object value)

Keeps the records whose field holds exactly this value. The value is passed to the query as a bind variable, so you never escape quotes in text yourself. A null value keeps the records whose field is blank, as isNull() does. To compare with a relative date such as today, pass a QRY_Condition.DateLiteral.

Parameters

ParameterTypeDescription
valueObjectValue to compare against

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Name).equals('Acme Corp')
    .toList();
apex
global QRY_Builder.Builder equals(SObject record)

Adds an = condition comparing to an SObject's Id.

Parameters

ParameterTypeDescription
recordSObjectSObject whose Id to compare against

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Contact> contacts = QRY_Builder.selectFrom(Contact.SObjectType)
    .condition(Contact.AccountId).equals(account)
    .toList();

excludes ​

apex
global QRY_Builder.Builder excludes(List<Object> values)

Adds an EXCLUDES condition for multi-picklist fields.

Parameters

ParameterTypeDescription
valuesListValues that must not be selected

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Object> excluded = new List<Object>{'Inactive', 'Archived'};
List<Lead> leads = QRY_Builder.selectFrom(Lead.SObjectType)
    .condition('Tags__c').excludes(excluded)
    .toList();
apex
global QRY_Builder.Builder excludes(Set<Object> values)

Adds an EXCLUDES condition for multi-picklist fields using a Set.

Parameters

ParameterTypeDescription
valuesSetValues that must not be selected

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
Set<Object> excluded = new Set<Object>{'Inactive', 'Archived'};
List<Lead> leads = QRY_Builder.selectFrom(Lead.SObjectType)
    .condition('Tags__c').excludes(excluded)
    .toList();

excludesStrict ​

apex
global QRY_Builder.Builder excludesStrict(List<Object> values)

Adds an EXCLUDES condition with strict empty list handling.

Parameters

ParameterTypeDescription
valuesListValues that must not be selected (must not be null or empty)

Returns QRY_Builder.Builder — Builder for chaining

Throws

ExceptionDescription
IllegalArgumentExceptionif values is null or empty

Example

apex
List<Object> excluded = new List<Object>{'Inactive', 'Archived'};
List<Lead> leads = QRY_Builder.selectFrom(Lead.SObjectType)
    .condition('Tags__c').excludesStrict(excluded)
    .toList();
apex
global QRY_Builder.Builder excludesStrict(Set<Object> values)

Adds an EXCLUDES condition with strict empty set handling.

Parameters

ParameterTypeDescription
valuesSetValues that must not be selected (must not be null or empty)

Returns QRY_Builder.Builder — Builder for chaining

Throws

ExceptionDescription
IllegalArgumentExceptionif values is null or empty

Example

apex
Set<Object> excluded = new Set<Object>{'Inactive', 'Archived'};
List<Lead> leads = QRY_Builder.selectFrom(Lead.SObjectType)
    .condition('Tags__c').excludesStrict(excluded)
    .toList();

greaterThan ​

apex
global QRY_Builder.Builder greaterThan(Object value)

Keeps the records whose field is larger than this value; for a date or a time, later. The value is passed to the query as a bind variable. After a having method such as havingSumOf, it compares the aggregate of each group instead of each record.

Parameters

ParameterTypeDescription
valueObjectValue to compare against

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.AnnualRevenue).greaterThan(1000000)
    .toList();

greaterThanOrEquals ​

apex
global QRY_Builder.Builder greaterThanOrEquals(Object value)

Keeps the records whose field is equal to this value or larger; for a date or a time, the same or later. The value is passed to the query as a bind variable. After a having method such as havingSumOf, it compares the aggregate of each group instead of each record.

Parameters

ParameterTypeDescription
valueObjectValue to compare against

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.NumberOfEmployees).greaterThanOrEquals(100)
    .toList();

includes ​

apex
global QRY_Builder.Builder includes(List<Object> values)

Adds an INCLUDES condition for multi-picklist fields.

Parameters

ParameterTypeDescription
valuesListValues that must all be selected

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Object> interests = new List<Object>{'Technology', 'Finance'};
List<Lead> leads = QRY_Builder.selectFrom(Lead.SObjectType)
    .condition('Interests__c').includes(interests)
    .toList();
apex
global QRY_Builder.Builder includes(Set<Object> values)

Adds an INCLUDES condition for multi-picklist fields using a Set.

Parameters

ParameterTypeDescription
valuesSetValues that must all be selected

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
Set<Object> interests = new Set<Object>{'Technology', 'Finance'};
List<Lead> leads = QRY_Builder.selectFrom(Lead.SObjectType)
    .condition('Interests__c').includes(interests)
    .toList();

includesStrict ​

apex
global QRY_Builder.Builder includesStrict(List<Object> values)

Adds an INCLUDES condition with strict empty list handling.

Parameters

ParameterTypeDescription
valuesListValues that must all be selected (must not be null or empty)

Returns QRY_Builder.Builder — Builder for chaining

Throws

ExceptionDescription
IllegalArgumentExceptionif values is null or empty

Example

apex
List<Object> interests = new List<Object>{'Technology', 'Finance'};
List<Lead> leads = QRY_Builder.selectFrom(Lead.SObjectType)
    .condition('Interests__c').includesStrict(interests)
    .toList();
apex
global QRY_Builder.Builder includesStrict(Set<Object> values)

Adds an INCLUDES condition with strict empty set handling.

Parameters

ParameterTypeDescription
valuesSetValues that must all be selected (must not be null or empty)

Returns QRY_Builder.Builder — Builder for chaining

Throws

ExceptionDescription
IllegalArgumentExceptionif values is null or empty

Example

apex
Set<Object> interests = new Set<Object>{'Technology', 'Finance'};
List<Lead> leads = QRY_Builder.selectFrom(Lead.SObjectType)
    .condition('Interests__c').includesStrict(interests)
    .toList();

isIn ​

apex
global QRY_Builder.Builder isIn(List<Object> values)

Adds an IN condition using a List.

Parameters

ParameterTypeDescription
valuesListValues to include

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Object> types = new List<Object>{'Customer', 'Partner'};
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Type).isIn(types)
    .toList();
apex
global QRY_Builder.Builder isIn(List<SObject> records)

Adds an IN condition using a List of SObjects.

Parameters

ParameterTypeDescription
recordsListSObjects to include (their Ids will be matched)

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Contact> contacts = QRY_Builder.selectFrom(Contact.SObjectType)
    .condition(Contact.AccountId).isIn(parentAccounts)
    .toList();
apex
global QRY_Builder.Builder isIn(List<SObject> records, SObjectField field)

Adds an IN condition by extracting field values from SObjects. A record whose key field is blank is skipped, so it never matches a row whose field is blank.

Parameters

ParameterTypeDescription
recordsListSObjects to extract values from
fieldSObjectThe field to extract values from

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Id).isIn(contacts, Contact.AccountId)
    .toList();
apex
global QRY_Builder.Builder isIn(QRY_Builder.Builder subquery)

Adds a semi-join IN condition using a subquery.

Parameters

ParameterTypeDescription
subqueryQRY_Builder.BuilderBuilder representing the subquery

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
QRY_Builder.Builder subquery = QRY_Builder.selectFrom(Contact.SObjectType)
    .fields(new List<SObjectField>{Contact.AccountId})
    .condition(Contact.Email).isNotNull();
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Id).isIn(subquery)
    .toList();
apex
global QRY_Builder.Builder isIn(Set<Object> values)

Keeps the records whose field holds any one of these values. A null or empty set adds a condition that is never true, so this condition matches no record; the query still runs. The values are copied, so a later change to the set does not change the query.

Parameters

ParameterTypeDescription
valuesSetValues to include

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
Set<Object> industries = new Set<Object>{'Technology', 'Finance'};
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Industry).isIn(industries)
    .toList();

isInStrict ​

apex
global QRY_Builder.Builder isInStrict(List<Object> values)

Adds an IN condition with strict empty list handling.

Parameters

ParameterTypeDescription
valuesListValues to include (must not be null or empty)

Returns QRY_Builder.Builder — Builder for chaining

Throws

ExceptionDescription
IllegalArgumentExceptionif values is null or empty

Example

apex
List<Object> statuses = new List<Object>{'Active', 'Pending'};
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Type).isInStrict(statuses)
    .toList();
apex
global QRY_Builder.Builder isInStrict(List<SObject> records)

Adds an IN condition using SObjects with strict handling.

Parameters

ParameterTypeDescription
recordsListSObjects to include (must not be null or empty)

Returns QRY_Builder.Builder — Builder for chaining

Throws

ExceptionDescription
IllegalArgumentExceptionif records is null or empty

Example

apex
List<Account> parents = [SELECT Id FROM Account LIMIT 10];
List<Contact> contacts = QRY_Builder.selectFrom(Contact.SObjectType)
    .condition(Contact.AccountId).isInStrict(parents)
    .toList();
apex
global QRY_Builder.Builder isInStrict(List<SObject> records, SObjectField field)

Adds an IN condition by extracting field values with strict handling. A record whose key field is blank is skipped, so it never matches a row whose field is blank.

Parameters

ParameterTypeDescription
recordsListSObjects to extract values from (must not be null or empty)
fieldSObjectThe field to extract values from

Returns QRY_Builder.Builder — Builder for chaining

Throws

ExceptionDescription
IllegalArgumentExceptionif records is null or empty, or no record has a value in the field

Example

apex
List<Contact> contacts = [SELECT AccountId FROM Contact LIMIT 10];
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Id).isInStrict(contacts, Contact.AccountId)
    .toList();
apex
global QRY_Builder.Builder isInStrict(Set<Object> values)

Adds an IN condition with strict empty set handling.

Parameters

ParameterTypeDescription
valuesSetValues to include (must not be null or empty)

Returns QRY_Builder.Builder — Builder for chaining

Throws

ExceptionDescription
IllegalArgumentExceptionif values is null or empty

Example

apex
Set<Object> statuses = new Set<Object>{'Active', 'Pending'};
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Type).isInStrict(statuses)
    .toList();

isNotNull ​

apex
global QRY_Builder.Builder isNotNull()

Keeps the records whose field has a value. It writes "field != null" into the query, the same as notEquals(null).

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Contact> contacts = QRY_Builder.selectFrom(Contact.SObjectType)
    .condition(Contact.Email).isNotNull()
    .toList();

isNull ​

apex
global QRY_Builder.Builder isNull()

Keeps the records whose field is blank. It writes "field = null" into the query, the same as equals(null).

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Contact> contacts = QRY_Builder.selectFrom(Contact.SObjectType)
    .condition(Contact.Email).isNull()
    .toList();

lessThan ​

apex
global QRY_Builder.Builder lessThan(Object value)

Keeps the records whose field is smaller than this value; for a date or a time, earlier. The value is passed to the query as a bind variable. After a having method such as havingSumOf, it compares the aggregate of each group instead of each record.

Parameters

ParameterTypeDescription
valueObjectValue to compare against

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.AnnualRevenue).lessThan(50000)
    .toList();

lessThanOrEquals ​

apex
global QRY_Builder.Builder lessThanOrEquals(Object value)

Keeps the records whose field is equal to this value or smaller; for a date or a time, the same or earlier. The value is passed to the query as a bind variable. After a having method such as havingSumOf, it compares the aggregate of each group instead of each record.

Parameters

ParameterTypeDescription
valueObjectValue to compare against

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.NumberOfEmployees).lessThanOrEquals(10)
    .toList();

notEquals ​

apex
global QRY_Builder.Builder notEquals(Object value)

Leaves out the records whose field holds exactly this value. The value is passed to the query as a bind variable, so you never escape quotes in text yourself. A null value keeps the records whose field has a value, as isNotNull() does.

Parameters

ParameterTypeDescription
valueObjectValue to compare against

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Industry).notEquals('Government')
    .toList();
apex
global QRY_Builder.Builder notEquals(SObject record)

Adds a != condition comparing to an SObject's Id.

Parameters

ParameterTypeDescription
recordSObjectSObject whose Id to exclude

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Contact> contacts = QRY_Builder.selectFrom(Contact.SObjectType)
    .condition(Contact.AccountId).notEquals(excludedAccount)
    .toList();

notIn ​

apex
global QRY_Builder.Builder notIn(QRY_Builder.Builder subquery)

Adds an anti-join NOT IN condition using a subquery.

Parameters

ParameterTypeDescription
subqueryQRY_Builder.BuilderBuilder representing the subquery

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
QRY_Builder.Builder subquery = QRY_Builder.selectFrom(Contact.SObjectType)
    .fields(new List<SObjectField>{Contact.AccountId})
    .condition(Contact.HasOptedOutOfEmail).equals(true);
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Id).notIn(subquery)
    .toList();

notInSet ​

apex
global QRY_Builder.Builder notInSet(List<Object> values)

Adds a NOT IN condition using a List.

Parameters

ParameterTypeDescription
valuesListValues to exclude

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Object> excluded = new List<Object>{'Competitor', 'Other'};
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Type).notInSet(excluded)
    .toList();
apex
global QRY_Builder.Builder notInSet(List<SObject> records)

Adds a NOT IN condition using a List of SObjects.

Parameters

ParameterTypeDescription
recordsListSObjects to exclude

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Account> excluded = [SELECT Id FROM Account WHERE Type = 'Competitor'];
List<Contact> contacts = QRY_Builder.selectFrom(Contact.SObjectType)
    .condition(Contact.AccountId).notInSet(excluded)
    .toList();
apex
global QRY_Builder.Builder notInSet(List<SObject> records, SObjectField field)

Adds a NOT IN condition by extracting field values from SObjects. A record whose key field is blank is kept, so rows whose field is blank are left out of the result too.

Parameters

ParameterTypeDescription
recordsListSObjects to extract values from
fieldSObjectThe field to extract values from

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Contact> contacts = [SELECT AccountId FROM Contact WHERE IsDeleted = true];
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Id).notInSet(contacts, Contact.AccountId)
    .toList();
apex
global QRY_Builder.Builder notInSet(Set<Object> values)

Leaves out the records whose field holds any one of these values. A null or empty set adds no condition, so no record is left out; isIn() does the opposite and matches nothing. The values are copied, so a later change to the set does not change the query.

Parameters

ParameterTypeDescription
valuesSetValues to exclude

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
Set<Object> excluded = new Set<Object>{'Competitor', 'Other'};
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Type).notInSet(excluded)
    .toList();

notInSetStrict ​

apex
global QRY_Builder.Builder notInSetStrict(List<Object> values)

Adds a NOT IN condition with strict empty list handling.

Parameters

ParameterTypeDescription
valuesListValues to exclude (must not be null or empty)

Returns QRY_Builder.Builder — Builder for chaining

Throws

ExceptionDescription
IllegalArgumentExceptionif values is null or empty

Example

apex
List<Object> excluded = new List<Object>{'Competitor', 'Other'};
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Type).notInSetStrict(excluded)
    .toList();
apex
global QRY_Builder.Builder notInSetStrict(List<SObject> records)

Adds a NOT IN condition using SObjects with strict handling.

Parameters

ParameterTypeDescription
recordsListSObjects to exclude (must not be null or empty)

Returns QRY_Builder.Builder — Builder for chaining

Throws

ExceptionDescription
IllegalArgumentExceptionif records is null or empty

Example

apex
List<Account> excluded = [SELECT Id FROM Account WHERE Type = 'Competitor'];
List<Contact> contacts = QRY_Builder.selectFrom(Contact.SObjectType)
    .condition(Contact.AccountId).notInSetStrict(excluded)
    .toList();
apex
global QRY_Builder.Builder notInSetStrict(List<SObject> records, SObjectField field)

Adds a NOT IN condition by extracting field values with strict handling. A record whose key field is blank is kept, so rows whose field is blank are left out of the result too.

Parameters

ParameterTypeDescription
recordsListSObjects to extract values from (must not be null or empty)
fieldSObjectThe field to extract values from

Returns QRY_Builder.Builder — Builder for chaining

Throws

ExceptionDescription
IllegalArgumentExceptionif records is null or empty, or every record in it is null

Example

apex
List<Contact> contacts = [SELECT AccountId FROM Contact WHERE IsDeleted = true];
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Id).notInSetStrict(contacts, Contact.AccountId)
    .toList();
apex
global QRY_Builder.Builder notInSetStrict(Set<Object> values)

Adds a NOT IN condition with strict empty set handling.

Parameters

ParameterTypeDescription
valuesSetValues to exclude (must not be null or empty)

Returns QRY_Builder.Builder — Builder for chaining

Throws

ExceptionDescription
IllegalArgumentExceptionif values is null or empty

Example

apex
Set<Object> excluded = new Set<Object>{'Competitor', 'Other'};
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Type).notInSetStrict(excluded)
    .toList();

startsWith ​

apex
global QRY_Builder.Builder startsWith(String value)

Adds a LIKE condition with wildcard at end (starts with).

Parameters

ParameterTypeDescription
valueStringText prefix

Returns QRY_Builder.Builder — Builder for chaining

Example

apex
List<Account> accounts = QRY_Builder.selectFrom(Account.SObjectType)
    .condition(Account.Name).startsWith('Acme')
    .toList();