Experience Salesforce

SOQL Aggregate Functions

What You’ll Learn

  • SOQL Aggregate Functions

SOQL Aggregate  Functions

“SOQL Aggregate Functions” shows a calculated result from the query and returns AggregateResult.

Any query that includes an aggregate function returns its results in an array of AggregateResult objects. AggregateResult is a read-only sObject and is only used for query results.

1. Sum():

AggregateResult ar = [SELECT SUM(Max_Salary__c)
FROM Position__c WHERE Max_Salary__c > 10000
];

2. Max():

Max(): AggregateResult ar = [SELECT MAX(Max_Salary__c)
FROM Position__c
WHERE Max_Salary__c > 10000
];

3. Min():

Min(): AggregateResult ar = [SELECT MIN(Max_Salary__c)
FROM Position__c
WHERE Max_Salary__c
];

4. Count() and Count(fieldName):

Integer i = [SELECT count(ID) FROM Account];

5. Avg():

Avg(): AggregateResult ar = [SELECT AVG(Min_Salary__c)
FROM Position__c
WHERE Max_Salary__c < 5000
];

6. Count_Distinct():

Count_Distinct(): AggregateResult ar = [SELECT COUNT_DISTINCT(Name)
FROM Position__c
];
Next Topic

Need Extra Support? Our FREE study materials have got you covered.

Our expert-prepared study materials provide the answers you need. Clear your doubts and improve your skills with detailed notes from industry professionals.

cts-img
Rakshabandhan Sale