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
122122 

problem in displaying aggregate results on visual force page

Hi,

 

Below is my visual force page and controller.

 

 

<apex:page standardController="Account"  extensions="MyPolicy"  >
  <apex:pageBlock title="Channel Performance Report" >
        <apex:pageBlockTable value="{!Results}" var="item" >
                  <apex:column value="{!item.Total}"  headerValue="Premium"/>

         
                                          </apex:pageBlockTable>  
                                                    </apex:pageBlock>
</apex:page>

 

 

 

 

 

public MyPolicy(ApexPages.StandardController controller) {
  }


public list<AggregateResult> AccountPolicy = new list<AggregateResult>();

 public MyPolicy(){

AccountPolicy= [SELECT Channel_Name__r.Channel_Id__c,COUNT(Sum_Of_Premium__c) Total from Policy__c GROUP BY Channel_Name__r.Channel_Id__c];

}
  public list<OppClass> getResults()  
{  
list<OppClass> lstResult = new list<OppClass>();  
for (AggregateResult ar: AccountPolicy)  
{  
oppClass objOppClass = new oppClass(ar);  
lstResult.add(objOppClass);  
}  
return lstResult;  
}  
 
class oppClass  
{  
public Integer Total  
{ get;set; }  
 
 
public oppClass(AggregateResult ar)  
{  
Total = (Integer)ar.get('Total');
 System.debug('total' + ar.get('Total'));
  
}  
}  
}

 

 

from the above code, i am trying to display total value on to the page. but no value  is displaying.

Please help me in achieving this. 

 

 

SFRichSFRich

You are very close. Here are a few suggestions: You need to alias every field in the SOQL statement (channel id) . The result from the SOQL should be typed AggregateResult.

 

public MyPolicy(ApexPages.StandardController controller) {
  }


public list<AggregateResult> AccountPolicy = new list<AggregateResult>();

 public MyPolicy(){

List<AggregateResult> ChannelResultList = [
SELECT Channel_Name__r.Channel_Id__c Channel_Id ,
COUNT(Sum_Of_Premium?__c) Total
from Policy__c GROUP BY Channel_Name__r.Channel_Id__c];

}
  public list<OppClass> getResults() 

list<OppClass> lstResult = new list<OppClass>(); 


for (AggregateResult ar: ChannelResultList) 

oppClass objOppClass = new oppClass(ar); 
lstResult.add(objOppClass); 

return lstResult; 

 
class oppClass 

public Integer Total 
{ get;set; } 

 
 
public oppClass(AggregateResult ar) 


Total = (Integer)ar.get('Total');
 System.debug('total' + ar.get('Total'));
 


}