Skip to main content

Filter

Specify and adjust single condition.

predefinied

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();

fields

with 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.with(Account.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.with(Account.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.with(Account.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.with(Account.Name).containsSome(names))
.toList();

contains

  • WHERE Name LIKE '%My%'

Signature

Filter contains(String value)

Example

SELECT Id
FROM Account
WHERE Name = '%My%'
SOQL.of(Contact.SObjectType)
.whereAre(SOQL.Filter.with(Account.Name).contains('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.with(Account.Name).endsWith('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.with(Account.Name).startsWith('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

  • 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

  • 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();

additional

removeWhenNull

Condition will be removed when filter's value is null.

Signature

Filter removeWhenNull()

Example

SELECT Id
FROM Account
String accountName = null;

SOQL.of(Account.SObjectType)
.whereAre(SOQL.Filter.with(Account.Name).equal(accountName).removeWhenNull())
.toList();