Free Salesforce Developers Tutorials >

Chapter 6 - SOQL >

SOQL Aggregate Functions

SOQL Aggregate Functions

What You’ll Learn

S2 Labs

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

Download Study Material

Get access to exclusive study material for Salesforce Certification and ace your exams!

Download Now

Our Salesforce Certification Courses

Hey there! Glad you made it through our Salesforce Developer Training for beginners . But wait! We've got some high-in-demand Salesforce courses for you to take your Salesforce skills to the next level, making you a desired professional in the Salesforce job market.

Post a Comment

Your email address will not be published. Required fields are marked *