v3.1.0
08-November-2023
- Changes
- AVG
- COUNT_DISTINCT
- MIN
- MAX
- SUM
ignoreWhen
for FilterGroup- Code refactoring
AVG
Introducing the avg
method.
Queryable avg(SObjectField field);
Queryable avg(SObjectField field, String alias);
// SELECT CampaignId, AVG(Amount) amount
// FROM Opportunity
// GROUP BY CampaignId
SOQL.of(Opportunity.SObjectType)
.with(Opportunity.CampaignId)
.avg(Opportunity.Amount)
.groupBy(Opportunity.CampaignId)
.toAggregated();
// SELECT CampaignId, AVG(Amount) amount
// FROM Opportunity
// GROUP BY CampaignId
SOQL.of(Opportunity.SObjectType)
.with(Opportunity.CampaignId)
.avg(Opportunity.Amount, 'amount')
.groupBy(Opportunity.CampaignId)
.toAggregated();
COUNT_DISTINCT
Introducing the countDistinct
method.
Queryable countDistinct(SObjectField field);
Queryable countDistinct(SObjectField field, String alias);
// SELECT COUNT_DISTINCT(Company) FROM Lead
SOQL.of(Lead.SObjectType)
.countDistinct(Lead.Company)
.toAggregated();
// SELECT COUNT_DISTINCT(Company) company FROM Lead
SOQL.of(Lead.SObjectType)
.countDistinct(Lead.Company, 'company')
.toAggregated();
MIN
Introducing the min
method.
Queryable min(SObjectField field);
Queryable min(SObjectField field, String alias);
// SELECT FirstName, LastName, MIN(CreatedDate)
// FROM Contact
// GROUP BY FirstName, LastName
SOQL.of(Contact.SObjectType)
.with(Contact.FirstName, Contact.LastName)
.min(Contact.CreatedDate)
.groupBy(Contact.FirstName)
.groupBy(Contact.LastName)
.toAggregated();
// SELECT FirstName, LastName, MIN(CreatedDate) createdDate
// FROM Contact
// GROUP BY FirstName, LastName
SOQL.of(Contact.SObjectType)
.with(Contact.FirstName, Contact.LastName)
.min(Contact.CreatedDate, 'createdDate')
.groupBy(Contact.FirstName)
groupBy(Contact.LastName)
.toAggregated();
MAX
Introducing the max
method.
Queryable max(SObjectField field);
Queryable max(SObjectField field, String alias);
// SELECT Name, MAX(BudgetedCost)
// FROM Campaign
// GROUP BY Name
SOQL.of(Campaign.SObjectType)
.with(Campaign.Name)
.max(Campaign.BudgetedCost)
.groupBy(Campaign.Name)
.toAggregated();
// SELECT Name, MAX(BudgetedCost) budgetedCost
// FROM Campaign
// GROUP BY Name
SOQL.of(Campaign.SObjectType)
.with(Campaign.Name)
.max(Campaign.BudgetedCost, 'budgetedCost')
.groupBy(Campaign.Name)
.toAggregated();
SUM
Introducing the sum
method.
Queryable sum(SObjectField field);
Queryable sum(SObjectField field, String alias);
// SELECT SUM(Amount) FROM Opportunity
SOQL.of(Opportunity.SObjectType)
.sum(Opportunity.Amount)
.toAggregated()
// SELECT SUM(Amount) amount FROM Opportunity
SOQL.of(Opportunity.SObjectType)
.sum(Opportunity.Amount, 'amount')
.toAggregated()
ignoreWhen for FilterGroup
The ignoreWhen
method was previously available only for Filter
, but now you can use it for FilterGroup
.
Boolean isPartnerUser = false;
SOQL.of(Account.SObjectType)
.whereAre(SOQL.FilterGroup
.add(SOQL.FilterGroup
.add(SOQL.Filter.with(Account.BillingCity).equal('Krakow'))
.add(SOQL.Filter.with(Account.BillingCity).equal('Warsaw'))
.anyConditionMatching()
.ignoreWhen(!isPartnerUser) // <===
)
.add(SOQL.FilterGroup
.add(SOQL.Filter.with(Account.Industry).equal('IT'))
.add(SOQL.Filter.name().contains('MyAcccount'))
)
)
.toList();