HavingFilter
Specify and adjust single having condition.
SOQL.of(Lead.SObjectType)
.sum(Lead.AnnualRevenue)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilter.sum(Lead.AnnualRevenue).greaterThan(1000000))
.toAggregated();
Methods​
The following are methods for HavingFilter
.
with(SObjectField field)
with(String field)
count(SObjectField field)
countDistinct(SObjectField field)
min(SObjectField field)
max(SObjectField field)
sum(SObjectField field)
isNull()
isNotNull()
isTrue()
isFalse()
equal(Object value)
notEqual(Object value)
lessThan(Object value)
greaterThan(Object value)
lessOrEqual(Object value)
greaterOrEqual(Object value)
contains(String value)
contains(String prefix, String value, String suffix)
notContains(String value)
notContains(String prefix, String value, String suffix)
endsWith(String value)
notEndsWith(String value)
startsWith(String value)
notStartsWith(String value)
isIn(Iterable<Object> iterable)
notIn(Iterable<Object> iterable)
FIELDS​
with sobject field​
Specify field that should be used in the having condition.
Signature
HavingFilter with(SObjectField field)
Example
SELECT COUNT(Name)
FROM Lead
GROUP BY City
HAVING City LIKE 'San%'
SOQL.of(Lead.SObjectType)
.count(Lead.Name)
.groupBy(Lead.City)
.have(SOQL.HavingFilter.with(Lead.City).startsWith('San'))
.toAggregated();
with string field​
Specify fields that should be used in the condition.
Signature
HavingFilter with(String field)
Example
SELECT COUNT(Name)
FROM Lead
GROUP BY City
HAVING City LIKE 'San%'
SOQL.of(Lead.SObjectType)
.with(Lead.LeadSource)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilter.with('City').startsWith('San'))
.toAggregated();
count​
Returns the number of rows matching the query criteria.
Signature
HavingFilter count(SObjectField field)
Example
SELECT LeadSource
FROM Lead
GROUP BY LeadSource
HAVING COUNT(Name) > 100
SOQL.of(Lead.SObjectType)
.with(Lead.LeadSource)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilter.count(Lead.Name).greaterThan(100))
.toAggregated();
countDistinct​
Returns the number of distinct non-null field values matching the query criteria.
Signature
HavingFilter countDistinct(SObjectField field)
Example
SELECT LeadSource
FROM Lead
GROUP BY LeadSource
HAVING COUNT_DISTINCT(Name) > 100
SOQL.of(Lead.SObjectType)
.with(Lead.LeadSource)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilter.countDistinct(Lead.Name).greaterThan(100))
.toAggregated();
min​
Returns the minimum value of a field.
Signature
HavingFilter min(SObjectField field)
Example
SELECT LeadSource
FROM Lead
GROUP BY LeadSource
HAVING MIN(NumberOfEmployees) > 100
SOQL.of(Lead.SObjectType)
.with(Lead.LeadSource)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilter.min(Lead.NumberOfEmployees).greaterThan(100))
.toAggregated();
max​
Returns the maximum value of a field.
Signature
HavingFilter min(SObjectField field)
Example
SELECT LeadSource
FROM Lead
GROUP BY LeadSource
HAVING MAX(NumberOfEmployees) < 100
SOQL.of(Lead.SObjectType)
.with(Lead.LeadSource)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilter.max(Lead.NumberOfEmployees).lessThan(100))
.toAggregated();
sum​
Returns the total sum of a numeric field.
Signature
HavingFilter min(SObjectField field)
Example
SELECT LeadSource
FROM Lead
GROUP BY LeadSource
HAVING SUM(AnnualRevenue) > 1000000
SOQL.of(Lead.SObjectType)
.with(Lead.LeadSource)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilter.sum(Lead.AnnualRevenue).greaterThan(1000000))
.toAggregated();
COMPERATORS​
isNull​
HAVING LeadSource = NULL
Signature
HavingFilter isNull()
Example
SELECT COUNT(Name)
FROM Lead
GROUP BY LeadSource
HAVING LeadSource = NULL
SOQL.of(Lead.SObjectType)
.count(Lead.Name)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilter.with(Lead.LeadSource).isNull())
.toAggregated();
isNotNull​
HAVING LeadSource != NULL
Signature
HavingFilter isNotNull()
Example
SELECT COUNT(Name)
FROM Lead
GROUP BY LeadSource
HAVING LeadSource != NULL
SOQL.of(Lead.SObjectType)
.count(Lead.Name)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilter.with(Lead.LeadSource).isNotNull())
.toAggregated();
isTrue​
HAVING IsConverted = TRUE
Signature
HavingFilter isTrue()
Example
SELECT COUNT(Name)
FROM Lead
GROUP BY IsConverted
HAVING IsConverted = TRUE
SOQL.of(Lead.SObjectType)
.count(Lead.Name)
.groupBy(Lead.IsConverted)
.have(SOQL.HavingFilter.with(Lead.IsConverted).isTrue())
.toAggregated();
isFalse​
HAVING IsConverted = FALSE
Signature
HavingFilter isFalse()
Example
SELECT COUNT(Name)
FROM Lead
GROUP BY IsConverted
HAVING IsConverted = FALSE
SOQL.of(Lead.SObjectType)
.count(Lead.Name)
.groupBy(Lead.IsConverted)
.have(SOQL.HavingFilter.with(Lead.IsConverted).isFalse())
.toAggregated();
equal​
HAVING City = 'Los Angeles'
HAVING SUM(AnnualRevenue) = 100000
Signature
HavingFilter equal(Object value)
Example
SELECT COUNT(Name)
FROM Lead
GROUP BY LeadSource
HAVING LeadSource = 'Web'
SELECT COUNT(Name)
FROM Lead
GROUP BY LeadSource
HAVING SUM(AnnualRevenue) = 10000
SOQL.of(Lead.SObjectType)
.count(Lead.Name)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilter.sum(Lead.AnnualRevenue).equal(10000))
.toAggregated();
SOQL.of(Lead.SObjectType)
.count(Lead.Name)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilter.with(Lead.LeadSource).equal('Web'))
.toAggregated();
notEqual​
HAVING City != 'Los Angeles'
HAVING SUM(AnnualRevenue) != 100000
Signature
HavingFilter notEqual(Object value)
Example
SELECT COUNT(Name)
FROM Lead
GROUP BY LeadSource
HAVING LeadSource != 'Web'
SELECT COUNT(Name)
FROM Lead
GROUP BY LeadSource
HAVING SUM(AnnualRevenue) != 10000
SOQL.of(Lead.SObjectType)
.count(Lead.Name)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilter.sum(Lead.AnnualRevenue).notEqual(10000))
.toAggregated();
SOQL.of(Lead.SObjectType)
.count(Lead.Name)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilter.with(Lead.LeadSource).notEqual('Web'))
.toAggregated();
lessThan​
HAVING SUM(AnnualRevenue) < 10000
Signature
HavingFilter lessThan(Object value)
Example
SELECT COUNT(Name)
FROM Lead
GROUP BY LeadSource
HAVING SUM(AnnualRevenue) < 10000
SOQL.of(Lead.SObjectType)
.count(Lead.Name)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilter.sum(Lead.AnnualRevenue).lessThan(10000))
.toAggregated();
greaterThan​
HAVING SUM(AnnualRevenue) > 10000
Signature
HavingFilter greaterThan(Object value)
Example
SELECT COUNT(Name)
FROM Lead
GROUP BY LeadSource
HAVING SUM(AnnualRevenue) > 10000
SOQL.of(Lead.SObjectType)
.count(Lead.Name)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilter.sum(Lead.AnnualRevenue).greaterThan(10000))
.toAggregated();
lessOrEqual​
HAVING SUM(AnnualRevenue) <= 10000
Signature
HavingFilter lessOrEqual(Object value)
Example
SELECT COUNT(Name)
FROM Lead
GROUP BY LeadSource
HAVING SUM(AnnualRevenue) <= 10000
SOQL.of(Lead.SObjectType)
.count(Lead.Name)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilter.sum(Lead.AnnualRevenue).lessOrEqual(10000))
.toAggregated();
greaterOrEqual​
HAVING SUM(AnnualRevenue) >= 10000
Signature
HavingFilter greaterOrEqual(Object value)
Example
SELECT COUNT(Name)
FROM Lead
GROUP BY LeadSource
HAVING SUM(AnnualRevenue) >= 10000
SOQL.of(Lead.SObjectType)
.count(Lead.Name)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilter.sum(Lead.AnnualRevenue).greaterOrEqual(10000))
.toAggregated();
contains​
HAVING Name LIKE '%San%'
Signature
HavingFilter contains(String value)
HavingFilter contains(String prefix, String value, String suffix);
Example
SELECT SUM(AnnualRevenue)
FROM Lead
GROUP BY City
HAVING City LIKE '%San%'
SOQL.of(Lead.SObjectType)
.sum(Lead.AnnualRevenue)
.groupBy(Lead.City)
.have(SOQL.HavingFilter.with(Lead.City).contains('San'))
.toAggregated();
SOQL.of(Lead.SObjectType)
.sum(Lead.AnnualRevenue)
.groupBy(Lead.City)
.have(SOQL.HavingFilter.with(Lead.City).contains('_', 'San', '%'))
.toAggregated();
notContains​
HAVING NOT Name LIKE '%San%'
Signature
HavingFilter notContains(String value)
HavingFilter notContains(String prefix, String value, String suffix);
Example
SELECT SUM(AnnualRevenue)
FROM Lead
GROUP BY City
HAVING (NOT City LIKE '%San%')
SOQL.of(Lead.SObjectType)
.sum(Lead.AnnualRevenue)
.groupBy(Lead.City)
.have(SOQL.HavingFilter.with(Lead.City).notContains('San'))
.toAggregated();
SOQL.of(Lead.SObjectType)
.sum(Lead.AnnualRevenue)
.groupBy(Lead.City)
.have(SOQL.HavingFilter.with(Lead.City).notContains('_', 'San', '%'))
.toAggregated();
startsWith​
HAVING City LIKE 'San%'
Signature
HavingFilter startsWith(String value)
Example
SELECT SUM(AnnualRevenue)
FROM Lead
GROUP BY City
HAVING City LIKE 'San%'
SOQL.of(Lead.SObjectType)
.sum(Lead.AnnualRevenue)
.groupBy(Lead.City)
.have(SOQL.HavingFilter.with(Lead.City).startsWith('San'))
.toAggregated();
notStartsWith​
HAVING NOT City LIKE 'San%'
Signature
HavingFilter notStartsWith(String value)
Example
SELECT SUM(AnnualRevenue)
FROM Lead
GROUP BY City
HAVING (NOT City LIKE 'San%')
SOQL.of(Lead.SObjectType)
.sum(Lead.AnnualRevenue)
.groupBy(Lead.City)
.have(SOQL.HavingFilter.with(Lead.City).notStartsWith('San'))
.toAggregated();
endsWith​
HAVING City LIKE '%San'
Signature
HavingFilter endsWith(String value)
Example
SELECT SUM(AnnualRevenue)
FROM Lead
GROUP BY City
HAVING City LIKE '%San'
SOQL.of(Lead.SObjectType)
.sum(Lead.AnnualRevenue)
.groupBy(Lead.City)
.have(SOQL.HavingFilter.with(Lead.City).endsWith('San'))
.toAggregated();
notEndsWith​
HAVING NOT City LIKE '%San'
Signature
HavingFilter notEndsWith(String value)
Example
SELECT SUM(AnnualRevenue)
FROM Lead
GROUP BY City
HAVING (NOT City LIKE '%San')
SOQL.of(Lead.SObjectType)
.sum(Lead.AnnualRevenue)
.groupBy(Lead.City)
.have(SOQL.HavingFilter.with(Lead.City).notEndsWith('San'))
.toAggregated();
isIn​
HAVING City IN ('San Francisco', 'Los Angeles')
Signature
HavingFilter isIn(Iterable<Object> inList)
Example
SELECT SUM(AnnualRevenue)
FROM Lead
GROUP BY City
HAVING City IN ('San Francisco', 'Los Angeles')
SOQL.of(Lead.SObjectType)
.sum(Lead.AnnualRevenue)
.groupBy(Lead.City)
.have(SOQL.HavingFilter.with(Lead.City).isIn(new List<String>{ 'San Francisco', 'Los Angeles' }))
.toAggregated();
notIn​
HAVING City NOT IN ('San Francisco', 'Los Angeles')
Signature
HavingFilter notIn(Iterable<Object> inList)
Example
SELECT SUM(AnnualRevenue)
FROM Lead
GROUP BY City
HAVING City NOT IN ('San Francisco', 'Los Angeles')
SOQL.of(Lead.SObjectType)
.sum(Lead.AnnualRevenue)
.groupBy(Lead.City)
.have(SOQL.HavingFilter.with(Lead.City).notIn(new List<String>{ 'San Francisco', 'Los Angeles' }))
.toAggregated();