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
Mathew Andresen 5Mathew Andresen 5 

Adding additional rows to pageblock table


I wanted to add some additional rows to my pageblock table.  For example, I'm doing a top 10 opportunities, and I wanted

total opportuntities
total goal 
variance from goal.

Is this possible?   I figure I could make a custom class and piece together all the different pieces but I'm hoping there's a better easier solution, kind of like how you might do it when piecing together a regular table with apex repeat.

Hi Mathew,

Try  this -

<apex:commandButton value="Add Row" action="{!addrow}" />


         public class demo {
         public list<Opportunitie > accon{get;set;}
         public Opportunitie agnt{get;set;}   
     public demo(apexpages.standardcontroller controller )
             agnt = new Opportunitie ();
             accon= [select id,Name,total_opportuntities__c,total_goal__c,variance_from_goal__c from Opportunitie ]; 

 public void addrow() {        
       Opportunitie opp = new Opportunitie();
        opp.total_opportuntities__c= agnt.total_opportuntities__c;
        opp.total_goal__c= agnt.total_goal__c;
        opp.variance_from_goal__c =agnt.variance_from_goal__c ;
        accon.add(opp );
        //insert prodiscount;
Mathew Andresen 5Mathew Andresen 5
I ended up just going with the custom class wrapper.  Here is the final solution.
public class Top10OppAt90All_Class {
    public List<Opportunity> oppListStart {get; set;}
    OppWrapper newOpp;
    public List<OppWrapper> oppList  { get; set; }
    public aggregateResult aggOppTotal {get; set;}
    decimal oppClosedTotal;
    public decimal variance {get; set;}
    Goals__c goal;
    Decimal goalTotal;
    public Decimal oppTotal {get; set;}
    public Top10OppAt90All_Class() {
       oppList = new List<oppWrapper>();
            if (oppTotal == NULL) {oppTotal = 0;}
            if (oppListStart == NULL) { 
                oppListStart = [SELECT Name, StageName, Id, Amount,,, type, closedate FROM Opportunity 
                                                  WHERE StageName = 'A. Pending Sale' AND Amount != 0 AND Amount != NULL
                                                  ORDER BY Amount DESC LIMIT 10]; 
                aggOppTotal = [SELECT Sum(Amount) TotalAmount FROM Opportunity WHERE StageName = 'W. Win' AND CloseDate = THIS_QUARTER];
                goal = [SELECT Grand_Total_Revenue__c FROM Goals__c WHERE Start_Date_of_new_Quarter__c = THIS_QUARTER];
                goalTotal = goal.Grand_Total_Revenue__c;
                oppClosedTotal = (Decimal)aggOppTotal.get('TotalAmount');
            for (Opportunity opp:oppListStart) {
				newopp = new OppWrapper(, opp.CloseDate, opp.Amount,;
                system.debug('opp = ' + opp );
                system.debug('newopp = ' + newOpp);
                oppList.add(new OppWrapper(, opp.CloseDate, opp.Amount, );
                oppTotal = oppTotal + opp.amount;
        oppList.add(new OppWrapper('Total Open Opp', NULL, OppTotal, NULL));
        oppList.add(new OppWrapper('', NULL, NULL, NULL));
        oppList.add(new OppWrapper('Total Closed Opp', NULL, oppClosedTotal, NULL));
        oppList.add(new OppWrapper('Total Goal', NULL, goalTotal, NULL));
        Variance = oppTotal+OppClosedTotal - goalTotal;
      //  } catch (exception e) { system.debug(e); }    
        system.debug('oppList = ' + oppList);

    public class OppWrapper {
        public String name {get; set; }
        public Date closeDate {get; set; }
        public Decimal amount {get; set; }
        public String Id {get; set; }
        public  OppWrapper(String name, Date closedate, Decimal amount, String id) {
   = name;
            this.closeDate = closeDate;
            this.amount = amount;
   = id;


<apex:page controller="Top10OppAt90All_Class">
  <apex:pageBlock >
     <apex:pageBlockTable value="{!OppList}" var="opp" captionClass="tableHeader">
         <apex:column > 
             <apex:outputText value="{0,date,MM'/'dd'/'yyyy}"> <apex:param value="{!opp.CloseDate}" /> </apex:outputText>
             <apex:facet name="header">Date</apex:facet>
        <apex:column >
            <apex:facet name="header">Opportunity</apex:facet>
        <apex:outputLink value="{!if( != NULL, URLFOR($Action.Opportunity.View, opp.Id), NULL) }" > {!} </apex:outputLink>
                    <apex:facet name="footer" ><apex:outputPanel > Variance: &nbsp; 
        </apex:outputPanel> </apex:facet>
        <apex:column >
            <apex:facet name="header" >Amount</apex:facet>
            <apex:outputText value="{0,number,$###,###,##0}">
            <apex:param value="{!opp.Amount}"/> </apex:outputText> 
            <apex:facet name="footer" >
            <apex:outputText value="{0,number,$###,###,##0}">
            <apex:param value="{!variance}"/> </apex:outputText>