You need to sign in to do that
Don't have an account?
r naresh
how find aggregate function avg(amount) from opportunity
im getting error in vf if i use the compaign id as value of column .
apex cls
-----------------
public integer avg{get;set;}
list<AggregateResult> lAGR{get;set;}
public exampleongroupby()
{
lAGR=[select campaignid,AVG(amount) avg from Opportunity group by campaignid];
}
public list<opportunity> getResult()
{
list<opportunity> opp=new list<opportunity>();
for(AggregateResult agr:lAGR)
{
opportunity op=new opportunity(agr);
opp.add(op);
}
return opp;
}
class opportunity
{
public integer avg{get;set;}
public opportunity(AggregateResult agr)
{
}
}
}
vf page
------------
<apex:page controller="exampleongroupby">
<apex:form >
<apex:pageblock title="Test For AVG,COUNT(),COUNT_DISTINCT,MAX,MIN,SUM">
<apex:pageBlockTable value="{!Result}" var="aar">
<apex:column value="{!aar.avg}"/>
</apex:pageBlockTable>
</apex:pageblock>
</apex:form>
</apex:page>
thank u in advance
apex cls
-----------------
public integer avg{get;set;}
list<AggregateResult> lAGR{get;set;}
public exampleongroupby()
{
lAGR=[select campaignid,AVG(amount) avg from Opportunity group by campaignid];
}
public list<opportunity> getResult()
{
list<opportunity> opp=new list<opportunity>();
for(AggregateResult agr:lAGR)
{
opportunity op=new opportunity(agr);
opp.add(op);
}
return opp;
}
class opportunity
{
public integer avg{get;set;}
public opportunity(AggregateResult agr)
{
}
}
}
vf page
------------
<apex:page controller="exampleongroupby">
<apex:form >
<apex:pageblock title="Test For AVG,COUNT(),COUNT_DISTINCT,MAX,MIN,SUM">
<apex:pageBlockTable value="{!Result}" var="aar">
<apex:column value="{!aar.avg}"/>
</apex:pageBlockTable>
</apex:pageblock>
</apex:form>
</apex:page>
thank u in advance
Try the code below:
Class:
VF:
You forgot to set the value in your Opportunity contructor class:
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.