0

I want to display just one field with my report in Visualforce. Is there any way to do it without writing report in VF/creating new fields etc ? Just something like display grand total with report "A"? Got this but i have got error on my layout: Everything was working well with pageblock but i want to get it with variable to display just Amount(number) in blue square

Content cannot be displayed: Unknown property 'VisualforceArrayList.total'

<apex:page standardController="Account" extensions="AgentOA">
       <style>
                 body
                 {
                        font-family: Verdana;
                        font-size: 12px;
                        font-color: white;
                        background-color: black;
                 }
        </style>
        {!Account.Id}
<body>               
<apex:variable value="{!accounttotals}" var="a"/>
<apex:outputtext value="{!a.total.amount}"/>
</body>               
</apex:page>

Class:

public with sharing class AgentOA{
        public Account acct;
    public Id Current_Acc_Id {get;set;}
     public AgentOA(ApexPages.StandardController stdController) {
        this.acct = (Account)stdController.getRecord();
        Current_Acc_Id =acct.id;
    }

              public List<AccountTotal> getaccounttotals() {
        List<AccountTotal> accounttotals = new List<AccountTotal>();
        for(Account a:[SELECT name, 
                      (SELECT name,amount FROM opportunities)
                 from account
                 where Id=:Current_Acc_Id]){
             accounttotals.add(new AccountTotal(a));
            }
           return accounttotals;
         }    

        public class accountTotal 
        {
                public Account account { get; private set; }
                public Opportunity total { get; private set; }
                public accountTotal(Account a) 
                {
                    account = a;
                    total = new Opportunity(amount = 0);
                    for(Opportunity o:a.opportunities) 
                    {
                        if(o.amount != null) total.amount += o.amount;
                    }
                }   
        }
}
1
  • You can try creating formula Field in reports Jul 24, 2017 at 8:22

1 Answer 1

0

Introduce one public list of opportunity and display that in a page.

public List accTot {get;set;} //Newly introduced

Display the amount with repeat since you are retrieve those in list.

public with sharing class AgentOA{
        public Account acct;
    public Id Current_Acc_Id {get;set;}
    public List<AccountTotal> accTot {get;set;}  //Newly introduced

     public AgentOA(ApexPages.StandardController stdController) {
        this.acct = (Account)stdController.getRecord();
        Current_Acc_Id =acct.id;
    }

     public List<AccountTotal> getaccounttotals() 
     {
        List<AccountTotal> accounttotals = new List<AccountTotal>();
        for(Account a:[SELECT name, 
                      (SELECT name,amount FROM opportunities)
                 from account
                 where Id=:Current_Acc_Id]){
             accounttotals.add(new AccountTotal(a));
            }
            accTot  = accounttotals;
           return accounttotals;
     }    

        public class accountTotal 
        {
                public Account account { get; set; }
                public Opportunity total { get; set; }
                public accountTotal(Account a) 
                {
                    account = a;
                    total = new Opportunity(amount = 0);
                    for(Opportunity o:a.opportunities) 
                    {
                        if(o.amount != null) total.amount += o.amount;
                    }
                }   
        }
}

Page

<apex:page standardController="Account" extensions="AgentOA">
       <style>
                 body
                 {
                        font-family: Verdana;
                        font-size: 12px;
                        font-color: white;
                        background-color: black;
                 }
        </style>
        {!Account.Id}
<body>        
<br/>       
<apex:variable value="{!accounttotals}" var="a"/>
<!-- <apex:outputtext value="{!a.total.amount}"/> -->
<apex:repeat value="{!accTot}" var="b">
Total {!b.total.amount }
</apex:repeat>
</body>               
</apex:page>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .