FilterGroup
Create group of conditions.
Methods
The following are methods for FilterGroup.
ADD CONDITION
add
Allows to add multiple conditions.
Add a SOQL.Filter or SOQL.FilterGroup or String.
Signature
FilterGroup add(FilterGroup filterGroup)
FilterGroup add(Filter filter)
FilterGroup add(String dynamicCondition)
Example
SELECT Id
FROM Account
WHERE
Industry = 'IT' AND
Name = 'My Account' AND
NumberOfEmployees >= 10
// build conditions on fly
SOQL.FilterGroup group = SOQL.FilterGroup
.add(SOQL.Filter.name().equal('My Account'))
.add(SOQL.Filter.with(Account.NumberOfEmployees).greaterOrEqual(10));
SOQL.of(Account.SObjectType)
.whereAre(SOQL.FilterGroup
.add(SOQL.Filter.with(Account.Industry).equal('IT'))
.add(group)
).toList();
SOQL.of(Account.SObjectType)
.whereAre(SOQL.FilterGroup
.add(SOQL.Filter.with(Account.Industry).equal('IT'))
.add(SOQL.Filter.name().equal('My Account'))
.add(SOQL.Filter.with(Account.NumberOfEmployees).greaterOrEqual(10))
).toList();
SOQL.of(Account.SObjectType)
.whereAre(SOQL.FilterGroup
.add(SOQL.Filter.with(Account.Industry).equal('IT'))
.add(SOQL.Filter.name().equal('My Account'))
.add('NumberOfEmployees >= 10')
).toList();
ORDER
conditionLogic
Set conditions order for SOQL query.
When not specify all conditions will be with AND.
Signature
FilterGroup conditionLogic(String order)
Example
SELECT Id
FROM Account
WHERE (Name = 'My Account' AND NumberOfEmployees >= 10)
OR (Name = 'My Account' AND Industry = 'IT')
SOQL.of(Account.SObjectType)
.whereAre(SOQL.FilterGroup
.add(SOQL.Filter.with(Account.Name).equal('My Account'))
.add(SOQL.Filter.with(Account.NumberOfEmployees).greaterOrEqual(10))
.add(SOQL.Filter.with(Account.Industry).equal('IT'))
.conditionLogic('(1 AND 2) OR (1 AND 3)')
).toList();
anyConditionMatching
When the conditionLogic is not specified, all conditions are joined using the AND operator by default.
To change the default condition logic, you can utilize the anyConditionMatching method, which joins conditions using the OR operator.
Signature
FilterGroup anyConditionMatching()
Example
SELECT Id
FROM Account
WHERE Name = 'My Account' OR NumberOfEmployees >= 10
SOQL.of(Account.SObjectType)
.whereAre(SOQL.FilterGroup
.add(SOQL.Filter.with(Account.Name).equal('My Account'))
.add(SOQL.Filter.with(Account.NumberOfEmployees).greaterOrEqual(10))
.anyConditionMatching()
).toList();