function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Savi3Savi3 

AggregateResult

Hi,

 

  AggregateResult[] Ar = [Select sum(Field name ) total from contact ];

Double sum = 0;

if (Ar.size()>o){

String str = ' ' + Ar[0].get(''total);

sum = Double.valueof(str);

}

Can somone tell me why this total is using with sum(Fieldname)?? Similarly for Avg(fieldname) aver??

 

Thank you,

Sav3.

Gunners_23Gunners_23

Its because of the alias you have given in the select statement. Alias is not mandatory

 

SOQL Query

 

  AggregateResult[] Ar = [Select sum(Field name ) total from contact ];

 

SOQL Query Syntax in case of Aggregate field

 

  AggregateResult[] Ar = [Select Aggregate field  [Alias Name]  from contact ];