Skip to main content
Hi,

I want to display a list of accounts with the total opportunity values.  I believe I would need to make a custom class for this (let me know if there is an easyier way to do this).  But when I try and display in I'm running into problems.  The apex compiles, but the visualforce doesn't recongnize the variable.  I get the error "Unknown property 'AcctSumList.AccountName'"

Here is the relevant APEX

 

public List<AcctSumList> getAccountSummary() {

list<AcctSumList> acctSummary = new List<AcctSumList>();

List<AggregateResult> getList = [SELECT Account.Name, sum(amount) TotalAmount FROM Opportunity GROUP BY Account.Name LIMIT 10];

for(AggregateResult agg : getList) {

String AccountName = (string)agg.get('Account.Name');

Double TotalAmount = (double)agg.get('TotalAmount');

acctSummary.add(new AcctSumList(AccountName, TotalAmount));

}

return acctSummary;

}

public class AcctSumList {

public String AccountName;

public double AccountTotal;

public AcctSumList(String AccountName, double AccountTotal) {

this.AccountName = AccountName;

this.AccountTotal = AccountTotal;

}

}

And the visualforce where I try and put it in a table

<apex:pageBlockTable value="{!AccountSummary}" var="acct">

<apex:column value ="{!acct.AccountName}"/>

<apex:column value="{!acct.TotalAmount}"/>

</apex:pageBlockTable>

Thanks,
6 answers
  1. Feb 8, 2015, 7:36 PM
    Hello,

    Try the code below:

     

    public List<AcctSumList> getAccountSummary() {

    list<AcctSumList> acctSummary = new List<AcctSumList>();

    List<AggregateResult> getList = [SELECT Account.Name, sum(amount) TotalAmount FROM Opportunity GROUP BY Account.Name LIMIT 10];

    for(AggregateResult agg : getList) {

    String AccountName = (string)agg.get('Account.Name');

    Double TotalAmount = (double)agg.get('TotalAmount');

    acctSummary.add(new AcctSumList(AccountName, TotalAmount));

    }

    return acctSummary;

    }

    public class AcctSumList {

    public String AccountName { get; set; }

    public double AccountTotal { get ; set; }

    public AcctSumList(String AccountName, double AccountTotal) {

    this.AccountName = AccountName;

    this.AccountTotal = AccountTotal;

    }

    }

    You have to expose your variables using gettters and setters to allow you retrieving and setting values.

    Regards.

    Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.

0/9000