Skip to main content

Filter

Specify and adjust single condition.

Methods

The following are methods for Filter.

FIELDS

COMPERATORS

ADDITIONAL

FIELDS

id

  • WHERE Id = :accountId
  • WHERE Id IN :accountIds

Signature

Filter id()

Example

SELECT Id
FROM Account
WHERE Id = :accountId
SOQL.of(Account.SObjectType)
.whereAre(SOQL.Filter.id().equal(accountId))
.toList();

recordType

  • WHERE RecordType.DeveloperName = 'Partner'

Signature

Filter recordType()

Example

SELECT Id
FROM Account
WHERE RecordType.DeveloperName = 'Partner'
SOQL.of(Account.SObjectType)
.whereAre(SOQL.Filter.recordType().equal('Partner'))
.toList();

Name

  • WHERE Name = 'My Account'

Signature

Filter name()

Example

SELECT Id
FROM Account
WHERE Name = 'My Account'
SOQL.of(Account.SObjectType)
.whereAre(SOQL.Filter.name().equal('My Account'))
.toList();

with sobject field

Specify field that should be used in the condition.

Signature

Filter with(SObjectField field)

Example

SELECT Id
FROM Account
WHERE Name = 'My Account'
SOQL.of(Account.SObjectType)
.whereAre(SOQL.Filter.name().equal('My Account'))
.toList();

with string field

Specify fields that should be used in the condition.

Signature

Filter with(String field)

Example

SELECT Id
FROM Account
WHERE Name = 'My Account'
SOQL.of(Account.SObjectType)
.whereAre(SOQL.Filter.with('Name').equal('My Account'))
.toList();

Specify parent field that should be used in the condition.

Signature

Filter with(String relationshipPath, SObjectField field);

Example

SELECT Id
FROM Contact
WHERE Account.Name = 'My Account'
SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.with('Account', Account.Name).equal('My Account'))
.toList();

COMPERATORS

isNull

  • WHERE Industry = NULL

Signature

Filter isNull()

Example

SELECT Id
FROM Account
WHERE Account.Industry = NULL
SOQL.of(Account.SObjectType)
.whereAre(SOQL.Filter.with(Account.Industry).isNull())
.toList();

isNotNull

  • WHERE Industry != NULL

Signature

Filter isNotNull()

Example

SELECT Id
FROM Account
WHERE Account.Industry != NULL
SOQL.of(Account.SObjectType)
.whereAre(SOQL.Filter.with(Account.Industry).isNotNull())
.toList();

isTrue

  • WHERE IsDeleted = TRUE

Signature

Filter isTrue()

Example

SELECT Id
FROM Account
WHERE Account.IsDeleted = TRUE
SOQL.of(Account.SObjectType)
.whereAre(SOQL.Filter.with(Account.IsDeleted).isTrue())
.toList();

isFalse

  • WHERE IsDeleted = FALSE

Signature

Filter isFalse()

Example

SELECT Id
FROM Account
WHERE Account.IsDeleted != NULL
SOQL.of(Account.SObjectType)
.whereAre(SOQL.Filter.with(Account.IsDeleted).isFalse())
.toList();

equal

  • WHERE Name = 'My Account'
  • WHERE NumberOfEmployees = 10
  • WHERE IsDeleted = true

Signature

Filter equal(Object value)

Example

SELECT Id FROM Account WHERE Name = 'My Account'

SELECT Id FROM Account WHERE NumberOfEmployees = 10

SELECT Id FROM Account WHERE IsDeleted = true
SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.name().equal('My Account'))
.toList();

SOQL.of(Account.SObjectType)
.whereAre(SOQL.Filter.with(Account.NumberOfEmployees).equal(10))
.toList();

SOQL.of(Account.SObjectType)
.whereAre(SOQL.Filter.with(Account.IsDeleted).equal(true))
.toList();

notEqual

  • WHERE Name != 'My Account'
  • WHERE NumberOfEmployees != 10
  • WHERE IsDeleted != true

Signature

Filter notEqual(Object value)

Example

SELECT Id FROM Account WHERE Name != 'My Account'

SELECT Id FROM Account WHERE NumberOfEmployees != 10

SELECT Id FROM Account WHERE IsDeleted != true
SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.name().notEqual('My Account'))
.toList();

SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.with(Account.NumberOfEmployees).notEqual(10))
.toList();

SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.with(Account.IsDeleted).notEqual(true))
.toList();

lessThan

  • WHERE NumberOfEmployees < 10

Signature

Filter lessThan(Object value)

Example

SELECT Id
FROM Account
WHERE NumberOfEmployees < 10
SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.with(Account.NumberOfEmployees).lessThan(10))
.toList();

greaterThan

  • WHERE NumberOfEmployees > 10

Signature

Filter greaterThan(Object value)

Example

SELECT Id
FROM Account
WHERE NumberOfEmployees > 10
SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.with(Account.NumberOfEmployees).greaterThan(10))
toList();

lessOrEqual

  • WHERE NumberOfEmployees <= 10

Signature

Filter lessOrEqual(Object value)

Example

SELECT Id
FROM Account
WHERE NumberOfEmployees <= 10
SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.with(Account.NumberOfEmployees).lessOrEqual(10))
.toList();

greaterOrEqual

  • WHERE NumberOfEmployees >= 10

Signature

Filter greaterOrEqual(Object value)

Example

SELECT Id
FROM Account
WHERE NumberOfEmployees >= 10
SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.with(Account.NumberOfEmployees).greaterOrEqual(10))
.toList();

containsSome

  • WHERE Name LIKE ('My', 'Acc')

Signature

Filter containsSome(List<String> values)

Example

SELECT Id
FROM Account
WHERE Name LIKE ('My', 'Acc')
List<String> names = new List<String>{ 'Acc', 'My' };

SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.name().containsSome(names))
.toList();

contains

  • WHERE Name LIKE '%My%'

Signature

Filter contains(String value)
Filter contains(String prefix, String value, String suffix);

Example

SELECT Id
FROM Account
WHERE Name = '%My%'
SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.name().contains('My'))
.toList();

SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.name().contains('_', 'My', '%'))
.toList();

notcontains

  • WHERE NOT Name LIKE '%My%'

Signature

Filter notContains(String value)
Filter notContains(String prefix, String value, String suffix);

Example

SELECT Id
FROM Account
WHERE NOT Name LIKE '%My%'
SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.name().notContains('My'))
.toList();

SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.name().notContains('_', 'My', '%'))
.toList();

endsWith

  • WHERE Name LIKE '%My'

Signature

Filter endsWith(String value)

Example

SELECT Id
FROM Account
WHERE Name = '%My'
SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.name().endsWith('My'))
.toList();

notEndsWith

  • WHERE NOT Name LIKE '%My'

Signature

Filter notEndsWith(String value)

Example

SELECT Id
FROM Account
WHERE NOT Name LIKE '%My'
SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.name().notEndsWith('My'))
.toList();

startsWith

  • WHERE Name LIKE 'My%'

Signature

Filter startsWith(String value)

Example

SELECT Id
FROM Account
WHERE Name = 'My%'
SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.name().startsWith('My'))
.toList();

notStartsWith

  • WHERE NOT Name LIKE 'My%'

Signature

Filter notStartsWith(String value)

Example

SELECT Id
FROM Account
WHERE NOT Name LIKE 'My%'
SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.name().notStartsWith('My'))
.toList();

isIn

  • WHERE Id IN :accountIds

Signature

Filter isIn(List<Object> inList)

Example

SELECT Id
FROM Account
WHERE Id IN :accountIds
SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.with(Account.Id).isIn(accountIds))
.toList();

notIn

  • WHERE Id NOT IN :accountIds

Signature

Filter notIn(List<Object> inList)

Example

SELECT Id
FROM Account
WHERE Id NOT IN :accountIds
SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.with(Account.Id).notIn(accountIds))
.toList();

join query

isIn join query

  • WHERE Id IN (SELECT AccountId FROM Contact WHERE Name = 'My Contact')

Signature

Filter isIn(JoinQuery joinQuery)

Example

SELECT Id
FROM Account
WHERE Id IN (
SELECT AccountId
FROM Contact
WHERE Name = 'My Contact'
)
SOQL.of(Account.SObjectType)
.whereAre(SOQL.Filter.with(Account.Id).isIn(
SOQL.InnerJoin.of(Contact.SObjectType)
.with(Contact.AccountId)
.whereAre(SOQL.Filter.with(Contact.Name).equal('My Contact'))
)).toList();

notIn join query

  • WHERE Id NOT IN (SELECT AccountId FROM Contact WHERE Name = 'My Contact')

Signature

Filter notIn(JoinQuery joinQuery)

Example

SELECT Id
FROM Account
WHERE Id NOT IN (
SELECT AccountId
FROM Contact
WHERE Name = 'My Contact'
)
SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.with(Account.Id).notIn(
SOQL.InnerJoin.of(Contact.SObjectType)
.with(Contact.AccountId)
.whereAre(SOQL.Filter.with(Contact.Name).equal('My Contact'))
)).toList();

multi-select picklist

includesAll

  • WHERE Roles INCLUDES ('Business User;Decision Maker')

Signature

Filter includesAll(Iterable<String> iterable)

Example

SELECT Id
FROM AccountContactRelation
WHERE Roles INCLUDES ('Business User;Decision Maker')
List<String> roles = new List<String>{ 'Business User', 'Decision Maker' };

SOQL builder = SOQL.of(AccountContactRelation.SObjectType)
.with(AccountContactRelation.Id)
.whereAre(SOQL.Filter.with(AccountContactRelation.Roles).includesAll(roles));

includesSome

  • WHERE Roles INCLUDES ('Business User', 'Decision Maker')

Signature

Filter includesSome(Iterable<String> iterable)

Example

SELECT Id
FROM AccountContactRelation
WHERE Roles INCLUDES ('Business User', 'Decision Maker')
List<String> roles = new List<String>{ 'Business User', 'Decision Maker' };

SOQL builder = SOQL.of(AccountContactRelation.SObjectType)
.with(AccountContactRelation.Id)
.whereAre(SOQL.Filter.with(AccountContactRelation.Roles).includesSome(roles));

excludesAll

  • WHERE Roles EXCLUDES ('Business User', 'Decision Maker')

Signature

Filter excludesAll(Iterable<String> iterable)

Example

SELECT Id
FROM AccountContactRelation
WHERE Roles EXCLUDES ('Business User', 'Decision Maker')
List<String> roles = new List<String>{ 'Business User', 'Decision Maker' };

SOQL builder = SOQL.of(AccountContactRelation.SObjectType)
.with(AccountContactRelation.Id)
.whereAre(SOQL.Filter.with(AccountContactRelation.Roles).excludesAll(roles));

excludesSome

  • WHERE Roles EXCLUDES ('Business User;Decision Maker')

Signature

Filter excludesSome(Iterable<String> iterable)

Example

SELECT Id
FROM AccountContactRelation
WHERE Roles EXCLUDES ('Business User;Decision Maker')
List<String> roles = new List<String>{ 'Business User', 'Decision Maker' };

SOQL builder = SOQL.of(AccountContactRelation.SObjectType)
.with(AccountContactRelation.Id)
.whereAre(SOQL.Filter.with(AccountContactRelation.Roles).excludesSome(roles));

ADDITIONAL

asDateLiteral

Date Literals

SOQL Lib automatically binds all variables; however, Date Literals cannot be binded. To skip binding for Date Literals, add asDateLiteral() to your Filter.

Signature

Filter asDateLiteral();

Example

SELECT Id
FROM Account
WHERE CreatedDate > 'LAST_90_DAYS'
String accountName = '';

SOQL.of(Account.SObjectType)
.whereAre(SOQL.Filter.with(Account.CreatedDate).greaterThan('LAST_90_DAYS').asDateLiteral());
.toList();

ignoreWhen

Condition will be removed when logic expression will evaluate to true.

Note! It does not work when SOQL.FilterGroup.conditionLogic() was used.

Signature

Filter ignoreWhen(Boolean logicExpression);

Example

SELECT Id
FROM Account
WHERE BillingCity = 'Krakow'
String accountName = '';

SOQL.of(Account.SObjectType)
.whereAre(SOQL.FilterGroup
.add(SOQL.Filter.with(Account.BillingCity).equal('Krakow'))
.add(SOQL.Filter.name().contains(accountName).ignoreWhen(String.isEmpty(accountName)))
)
.toList();