Filter
Specify and adjust single condition.
Methods
The following are methods for Filter
.
id()
recordType()
name()
with(SObjectField field)
with(String field)
with(String relationshipName, SObjectField field)
isNull()
isNotNull()
isTrue()
isFalse()
equal(Object value)
notEqual(Object value)
lessThan(Object value)
greaterThan(Object value)
lessOrEqual(Object value)
greaterOrEqual(Object value)
containsSome(List<String> values)
contains(String value)
notContains(String value)
endsWith(String value)
notEndsWith(String value)
startsWith(String value)
notStartsWith(String value)
contains(String prefix, String value, String suffix)
notContains(String prefix, String value, String suffix)
isIn(Iterable<Object> iterable)
isIn(List<Object> inList)
isIn(InnerJoin joinQuery)
notIn(Iterable<Object> iterable)
notIn(List<Object> inList)
notIn(InnerJoin joinQuery)
includesAll(Iterable<String> values)
includesSome(Iterable<String> values)
excludesAll(Iterable<String> values)
excludesSome(Iterable<String> values)
FIELDS
id
WHERE Id = :accountId
WHERE Id IN :accountIds
Signature
Filter id()
Example
SELECT Id
FROM Account
WHERE Id = :accountId
SOSL.of(Account.SObjectType)
.whereAre(SOSL.Filter.id().equal(accountId))
.toList();
recordType
WHERE RecordType.DeveloperName = 'Partner'
Signature
Filter recordType()
Example
SELECT Id
FROM Account
WHERE RecordType.DeveloperName = 'Partner'
SOSL.of(Account.SObjectType)
.whereAre(SOSL.Filter.recordType().equal('Partner'))
.toList();
Name
WHERE Name = 'My Account'
Signature
Filter name()
Example
SELECT Id
FROM Account
WHERE Name = 'My Account'
SOSL.of(Account.SObjectType)
.whereAre(SOSL.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'
SOSL.of(Account.SObjectType)
.whereAre(SOSL.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'
SOSL.of(Account.SObjectType)
.whereAre(SOSL.Filter.with('Name').equal('My Account'))
.toList();
with related field
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'
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.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
SOSL.of(Account.SObjectType)
.whereAre(SOSL.Filter.with(Account.Industry).isNull())
.toList();
isNotNull
WHERE Industry != NULL
Signature
Filter isNotNull()
Example
SELECT Id
FROM Account
WHERE Account.Industry != NULL
SOSL.of(Account.SObjectType)
.whereAre(SOSL.Filter.with(Account.Industry).isNotNull())
.toList();
isTrue
WHERE IsDeleted = TRUE
Signature
Filter isTrue()
Example
SELECT Id
FROM Account
WHERE Account.IsDeleted = TRUE
SOSL.of(Account.SObjectType)
.whereAre(SOSL.Filter.with(Account.IsDeleted).isTrue())
.toList();
isFalse
WHERE IsDeleted = FALSE
Signature
Filter isFalse()
Example
SELECT Id
FROM Account
WHERE Account.IsDeleted != NULL
SOSL.of(Account.SObjectType)
.whereAre(SOSL.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
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.Filter.name().equal('My Account'))
.toList();
SOSL.of(Account.SObjectType)
.whereAre(SOSL.Filter.with(Account.NumberOfEmployees).equal(10))
.toList();
SOSL.of(Account.SObjectType)
.whereAre(SOSL.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
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.Filter.name().notEqual('My Account'))
.toList();
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.Filter.with(Account.NumberOfEmployees).notEqual(10))
.toList();
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.Filter.with(Account.IsDeleted).notEqual(true))
.toList();
lessThan
WHERE NumberOfEmployees < 10
Signature
Filter lessThan(Object value)
Example
SELECT Id
FROM Account
WHERE NumberOfEmployees < 10
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.Filter.with(Account.NumberOfEmployees).lessThan(10))
.toList();
greaterThan
WHERE NumberOfEmployees > 10
Signature
Filter greaterThan(Object value)
Example
SELECT Id
FROM Account
WHERE NumberOfEmployees > 10
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.Filter.with(Account.NumberOfEmployees).greaterThan(10))
toList();
lessOrEqual
WHERE NumberOfEmployees <= 10
Signature
Filter lessOrEqual(Object value)
Example
SELECT Id
FROM Account
WHERE NumberOfEmployees <= 10
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.Filter.with(Account.NumberOfEmployees).lessOrEqual(10))
.toList();
greaterOrEqual
WHERE NumberOfEmployees >= 10
Signature
Filter greaterOrEqual(Object value)
Example
SELECT Id
FROM Account
WHERE NumberOfEmployees >= 10
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.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' };
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.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%'
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.Filter.name().contains('My'))
.toList();
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.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%'
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.Filter.name().notContains('My'))
.toList();
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.Filter.name().notContains('_', 'My', '%'))
.toList();
endsWith
WHERE Name LIKE '%My'
Signature
Filter endsWith(String value)
Example
SELECT Id
FROM Account
WHERE Name = '%My'
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.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'
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.Filter.name().notEndsWith('My'))
.toList();
startsWith
WHERE Name LIKE 'My%'
Signature
Filter startsWith(String value)
Example
SELECT Id
FROM Account
WHERE Name = 'My%'
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.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%'
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.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
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.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
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.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'
)
SOSL.of(Account.SObjectType)
.whereAre(SOSL.Filter.with(Account.Id).isIn(
SOSL.InnerJoin.of(Contact.SObjectType)
.with(Contact.AccountId)
.whereAre(SOSL.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'
)
SOSL.of(Contact.SObjectType)
.whereAre(SOSL.Filter.with(Account.Id).notIn(
SOSL.InnerJoin.of(Contact.SObjectType)
.with(Contact.AccountId)
.whereAre(SOSL.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' };
SOSL builder = SOSL.of(AccountContactRelation.SObjectType)
.with(AccountContactRelation.Id)
.whereAre(SOSL.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' };
SOSL builder = SOSL.of(AccountContactRelation.SObjectType)
.with(AccountContactRelation.Id)
.whereAre(SOSL.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' };
SOSL builder = SOSL.of(AccountContactRelation.SObjectType)
.with(AccountContactRelation.Id)
.whereAre(SOSL.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' };
SOSL builder = SOSL.of(AccountContactRelation.SObjectType)
.with(AccountContactRelation.Id)
.whereAre(SOSL.Filter.with(AccountContactRelation.Roles).excludesSome(roles));
ADDITIONAL
asDateLiteral
SOSL 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 = '';
SOSL.of(Account.SObjectType)
.whereAre(SOSL.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 SOSL.FilterGroup.conditionLogic() was used.
Signature
Filter ignoreWhen(Boolean logicExpression);
Example
SELECT Id
FROM Account
WHERE BillingCity = 'Krakow'
String accountName = '';
SOSL.of(Account.SObjectType)
.whereAre(SOSL.FilterGroup
.add(SOSL.Filter.with(Account.BillingCity).equal('Krakow'))
.add(SOSL.Filter.name().contains(accountName).ignoreWhen(String.isEmpty(accountName)))
)
.toList();