Skip to content

v3.2.0

Choose a tag to compare

@pgajek2 pgajek2 released this 19 Dec 12:20
· 116 commits to main since this release
7796c88

19-December-2023

  • Changes
    • COUNT related
    • AVG related
    • COUNT_DISTINCT related
    • MIN related
    • MAX related
    • SUM related
    • toLabel
    • format
    • Code refactoring

COUNT

Introducing the count method for related fields.

Queryable count(String relationshipName, SObjectField field);
Queryable count(String relationshipName, SObjectField field, String alias);
// SELECT COUNT(Account.Name) 
// FROM Contact

SOQL.of(Contact.SObjectType)
    .count('Account', Account.Name)
    .toAggregated();
// SELECT COUNT(Account.Name) names 
// FROM Contact

SOQL.of(Contact.SObjectType)
    .count('Account', Account.Name, 'names')
    .toAggregated();

AVG

Introducing the avg method for related fields.

Queryable avg(String relationshipName, SObjectField field);
Queryable avg(String relationshipName, SObjectField field, String alias);
// SELECT AVG(Opportunity.Amount) 
// FROM OpportunityLineItem

SOQL.of(OpportunityLineItem.SObjectType)
    .avg('Opportunity', Opportunity.Amount)
    .toAggregate();
// SELECT AVG(Opportunity.Amount) amount 
// FROM OpportunityLineItem

SOQL.of(OpportunityLineItem.SObjectType)
    .avg('Opportunity', Opportunity.Amount, 'amount')
    .toAggregate();

COUNT_DISTINCT

Introducing the countDistinct method for related fields.

Queryable countDistinct(String relationshipName, SObjectField field);
Queryable countDistinct(String relationshipName, SObjectField field, String alias);
// SELECT COUNT_DISTINCT(Lead.Company) 
// FROM CampaignMember

SOQL.of(CampaignMember.SObjectType)
    .countDistinct('Lead', Lead.Company)
    .toAggregate();
// SELECT COUNT_DISTINCT(Lead.Company) company 
// FROM CampaignMember

SOQL.of(CampaignMember.SObjectType)
    .countDistinct('Lead', Lead.Company, 'company')
    .toAggregate();

MIN

Introducing the min method for related fields.

Queryable min(String relationshipName, SObjectField field);
Queryable min(String relationshipName, SObjectField field, String alias);
// SELECT MIN(Account.CreatedDate) 
// FROM Contact

SOQL.of(Contact.SObjectType)
    .min('Account', Account.CreatedDate)
    .toAggregate();
// SELECT MIN(Account.CreatedDate) createdDate 
// FROM Contact

SOQL.of(Contact.SObjectType)
    .min('Account', Account.CreatedDate, 'createdDate')
    .toAggregate();

MAX

Introducing the max method for related fields.

Queryable max(String relationshipName, SObjectField field);
Queryable max(String relationshipName, SObjectField field, String alias);
// SELECT MAX(Campaign.BudgetedCost) 
// FROM CampaignMember

SOQL.of(CampaignMember.SObjectType)
    .max('Campaign', Campaign.BudgetedCost)
    .toAggregate();
// SELECT MAX(Campaign.BudgetedCost) budgetedCost 
// FROM CampaignMember

SOQL.of(CampaignMember.SObjectType)
    .max('Campaign', Campaign.BudgetedCost, 'budgetedCost')
    .toAggregate();

SUM

Introducing the sum method for related fields.

Queryable sum(String relationshipName, SObjectField field);
Queryable sum(String relationshipName, SObjectField field, String alias);
// SELECT SUM(Opportunity.Amount)
// FROM OpportunityLineItem

SOQL.of(OpportunityLineItem.SObjectType)
    .sum('Opportunity', Opportunity.Amount)
    .toAggregate();
// SELECT SUM(Opportunity.Amount) amount 
// FROM OpportunityLineItem

SOQL.of(OpportunityLineItem.SObjectType)
    .sum('Opportunity', Opportunity.Amount, 'amount')
    .toAggregate();

toLabel

toLabel()

To translate SOQL query results into the language of the user who submits the query, use the toLabel method.

Queryable toLabel(SObjectField field);
Queryable toLabel(String field);
// SELECT Company, toLabel(Status) 
// FROM Lead

SOQL.of(Lead.SObjectType)
    .with(Lead.Company)
    .toLabel(Lead.Status)
    .toList();
// SELECT Company, toLabel(Recordtype.Name) 
// FROM Lead

SOQL.of(Lead.SObjectType)
    .with(Lead.Company)
    .toLabel('Recordtype.Name')
    .toList();

format

FORMAT()

Use FORMAT with the SELECT clause to apply localized formatting to standard and custom number, date, time, and currency fields.

Queryable format(SObjectField field);
Queryable format(SObjectField field, String alias);
// SELECT FORMAT(Amount)
// FROM Opportunity

SOQL.of(Opportunity.SObjectType)
    .format(Opportunity.Amount)
    .toList();
// SELECT FORMAT(Amount) amt 
// FROM Opportunity

SOQL.of(Opportunity.SObjectType)
    .format(Opportunity.Amount, 'amt')
    .toList();