06-October-2024
New
HAVING
support
HAVING
support
HAVING is an optional clause that can be used in a SOQL query to filter results that aggregate functions return.
You can use a HAVING clause with a GROUP BY clause to filter the results returned by aggregate functions, such as SUM(). The HAVING clause is similar to a WHERE clause. The difference is that you can include aggregate functions in a HAVING clause, but not in a WHERE clause.
Signature
Queryable have(HavingFilterGroup filterGroup);
Queryable have(HavingFilter filter);
Queryable have(String dynamicCondition);
Queryable havingConditionLogic(String order);
Queryable anyHavingConditionMatching();
Example
SOQL.of(Lead.SObjectType)
.with(Lead.LeadSource)
.count(Lead.Name)
.groupBy(Lead.City)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilterGroup
.add(SOQL.HavingFilter.count(Lead.Name).greaterThan(100))
.add(SOQL.HavingFilter.with(Lead.City).startsWith('San'))
)
.toAggregated();
SOQL.of(Lead.SObjectType)
.sum(Lead.AnnualRevenue)
.groupBy(Lead.LeadSource)
.have(SOQL.HavingFilter.sum(Lead.AnnualRevenue).greaterThan(1000000))
.toAggregated();
More details: