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
kevinedelmannkevinedelmann 

How show aggregate SUM values in VF Page

How do you show SUM aggregate values in a VF page.

 

First off I am not a full time programmer but can copy/modify code that I find online. The business case I have is that I need to show summary information from a custom object that is not related on an account using the external id of the account.  I.e. # of subscribers, total premiums, and the number of accounts.

 

I think I got the SOQL query correct but I cannot seem to get the information in a proper format to show up on my visualforce page.  I managed to do when I use COUNT but I cannot seem to get it to work correctly when I use SUM.

 

Also, I am using the standard Account Controller with an Extension.

 

Below is my Class & VF Page.

 

Thanks in advance for any and all help.


Kevin

 

CLASS

 

public class Agency_Client_Info
{
/*DECLARE VARIABLES */
public final Account acct;
public final Account acctINFO;
public list<AggregateResult> lstAR = new list<AggregateResult>();

/* 
Note that any query that includes an aggregate function returns its results in an array of 
AggregateResult objects. AggregateResult is a read-only sObject and is only used for query results. 
Aggregate functions become a more powerful tool to generate reports when you use them with a 
GROUP BY clause. For example, you could find the count of all opportunities for a CloseDate. 
*/  

public Agency_Client_Info(ApexPages.StandardController stdController)  
{
     /*Get the account information */
     this.acct = (Account)stdController.getRecord();
     acctINFO = [select External_ID__c from Account where ID =:acct.ID];
     
            lstAR=[ select count(ID) TotalSC, 
                    sum(Total_Subscribers__c) TotSubs,
                    sum(Earnedpremium_SUM__c) TotPrem
                    from Sub_Client__c where AOR1_TIN__c = :acctINFO.External_ID__c Or 
                                             AOR2_TIN__c = :acctINFO.External_ID__c
                                             ];
}

public list<AgencyInfoClass> getResults()
{
list<AgencyInfoClass> lstResult = new list<AgencyInfoClass>();  
for (AggregateResult ar: lstAR)  
{  
AgencyInfoClass objAgencyInfoClass = new AgencyInfoClass(ar);  
 lstResult.add(objAgencyInfoClass);  
}  
return lstResult;  
}  


//DEFINE CLASS TO HOLD THE INFORMATION TO BE PASSED
class AgencyInfoClass
{
public Decimal TotalSubs
{ get;set; }

public Decimal TotalPrem
{ get;set; }

public Integer TotalSC
{ get;set; }


//Convert the objects to type needed
public AgencyInfoClass(AggregateResult ar)
{
//Note that ar returns objects as results, so you need type conversion here
TotalSC =   (Integer)ar.get('TotalSC');
TotalSubs = (Decimal)ar.get('TotalSubs');
TotalPrem = (Decimal)ar.get('TotalPrem');

}
}

}

 

 

VF Page

 

<apex:page standardController="Account" extensions="Agency_Client_Info" standardStylesheets="true">

<apex:pageblocksection >
    <apex:pageBlockTable value="{!Results}" var="ar">
        <apex:column headerValue="# of Subs" value="{!ar.TotalSubs}"/>
        <apex:column headerValue="Earned Premium" value="{!ar.Totalprem}"/>

    </apex:pageBlockTable>
</apex:pageblocksection>
</apex:page>

 

 

beener3beener3

I've got the same problem.

The controller compiles, but the visualforce doesn't save. it insists that  :

Save error: Unknown property 'PayrollPaymentDateForExport.Payment_Deduction_Data'

 

  Where Payment_Deduction_Data is the name of the class I return and PayrollPaymentDateForExport is the name of my controller.
It seems to me that Visualforce doesn't like the custom child class, which was a necessity due to the way Aggegate results are returned.
Any ideas? Pretty please?