You need to sign in to do that
Don't have an account?

aggregate result issue
Hi
I need the average amount and sum of amount from opportunity grouped by stageName.
I have given the code, but the page is displaying same values for average and sum of amount.
Am I missing anything?
Thanks
pooja
I need the average amount and sum of amount from opportunity grouped by stageName.
I have given the code, but the page is displaying same values for average and sum of amount.
Am I missing anything?
global class AggregateExample { //3. public List<AggregateResult> aggrList=new List<AggregateResult>(); //4. public AggregateExample() { aggrList=[select StageName,AVG(Amount),SUM(Amount) from opportunity Group By StageName limit 50000]; } //5. create list object of wrapper class List<oppor_wrapper> opr=new List<oppor_wrapper>(); //6. global List<oppor_wrapper> getResultList() { for(AggregateResult ar:aggrList) { oppor_wrapper o=new oppor_wrapper(ar); opr.add(o); } return opr; } global class oppor_wrapper { //1. public String StageName{get;set;} public Decimal Amount{get;set;} //2. public oppor_wrapper(AggregateResult aggr) { this.StageName=(String)aggr.get('StageName'); this.Amount=(Double)aggr.get('expr0'); this.Amount=(Decimal)aggr.get('expr1'); } } } <apex:page controller="AggregateExample" contentType="vnd.ms-excel#reporting.xls> <apex:pageBlock title="Result"> <apex:pageBlockTable value="{!resultList}" var="o"> <apex:column value="{!o.stageName}" headerValue="StageName" /> <apex:column value="{!o.Amount}" headerValue="AverageAmount"/> <apex:column value="{!o.Amount}" headerValue="SumAmount"/> </apex:pageBlockTable> </apex:pageBlock> </apex:page>
Thanks
pooja
Visualforce Page
Apex Class
All Answers
Visualforce Page
Apex Class
thanks, I overlooked this issue.