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
akaaka 

How to display AggregateR​esult data in visualforc​e page.

public class in the
       AggregateResult [] gr =
            [select count (name) kazu, sum (Field5__c) ttl
            from CustomObject3__c
            group by Field4__c
            order by Field4__c DESC];
The results of the above
<apex:pageBlock>
Please tell me how do I know what I want to use the display.

help me!

Best Answer chosen by Admin (Salesforce Developers) 
Pradeep_NavatarPradeep_Navatar

Below is the sample code to display Aggregate Result on VF page :

 

Integer TotName=0;

AggregateResult [] gr = [select count (name) kazu, sum (Field5__c) ttl from CustomObject3__c group by Field4__c                order by Field4__c DESC];

 

for (AggregateResult ar : gr)

{

System.debug('Total Name' + ar.get('expr0'));

TotName = TotName + ar.get('expr0');

 

Use {!TotName} on VF page to display the Total Name value.

 

All Answers

Pradeep_NavatarPradeep_Navatar

Below is the sample code to display Aggregate Result on VF page :

 

Integer TotName=0;

AggregateResult [] gr = [select count (name) kazu, sum (Field5__c) ttl from CustomObject3__c group by Field4__c                order by Field4__c DESC];

 

for (AggregateResult ar : gr)

{

System.debug('Total Name' + ar.get('expr0'));

TotName = TotName + ar.get('expr0');

 

Use {!TotName} on VF page to display the Total Name value.

 

This was selected as the best answer
akaaka

Thank you Pradeep Navatar
But

 

TotName = TotName + ar.get ('expr0');
In the above formula
Error (Arithmetic expressions must use numeric arguments) is becoming?
I tried in another example,
Error (Arithmetic expressions must use numeric arguments) will be.

akaaka

             System.debug('kazu' + ar.get('kazu'));
             System.debug('ttl' + ar.get('ttl'));
             nen = string.valueOf(ar.get('mm'));
             kazu = integer.valueOf(ar.get('kazu'));
             ttl = Double.valueOf(ar.get('ttl'));
のようにコーディングしましたら

エラーは出なくなりました。

ありがとうございます