1

I have an aggregated list that counts the number of records from a custom object created by a user that I display on a visualforce page. I need to also display the same thing from a different custom object and display it in the same pageblock. Here is the controller code:

    public List<AggregateResult> top6Contributors1
{
    get
    {
        if (top6Contributors1 == null)
        {
            top6Contributors1 = [
                SELECT CreatedById, CreatedBy.Name name,
                    count(Id) contributions
                FROM Idea_Lobby__c
                GROUP BY CreatedById, CreatedBy.Name
                ORDER BY count(CreatedById) desc limit 6
            ];
        }


        return top6Contributors1;

    }
    private set;
}

Here is the vf code:

  <apex:pageBlock >
      <apex:repeat value="{!Top6Contributors1}" var="r">

      <div class="top-con"> 
      <img src="{!$Resource.Small_Icon}" alt="ideacenter" id="person1"/>
           <ul>
              <li><span id="Name"><h4>{!r['name']}</h4></span></li>
              <li>
                  <label>Ideas</label>
                  :<span id="ideas"> {!r['contributions']}</span></li>
              <li>
                   <label>Comments</label>
                  :<span id="votes"> </span></li>

           </ul>
     </div> 

     </apex:repeat> 
     </apex:pageBlock>    

How would I display them both?

1

Could you try adding this to your controller ?

public List<ContributionWrapper> getContributionsWrapper(){

    List<ContributionWrapper> lContributions = new List<ContributionWrapper>();

    for(AggregateResult aResult : top6Contributors1){
        lContributions.add(aResult);
    }

    return lContributions ;
}

public class ContributionWrapper{
    public String name {get;set;}
    public Integer contributions {get;set;}

    public ContributionWrapper(AggregateResult theResult){
        name = (String) theResult.get('name');
        contributions = (Integer) theResult.get('contributions');
    }
}

And then update your VF page with :

  <apex:pageBlock >
      <apex:repeat value="{!contributionsWrapper}" var="r">

      <div class="top-con"> 
      <img src="{!$Resource.Small_Icon}" alt="ideacenter" id="person1"/>
           <ul>
              <li><span id="Name"><h4>{!r.name}</h4></span></li>
              <li>
                  <label>Ideas</label>
                  :<span id="ideas"> {!r.contributions}</span></li>
              <li>
                   <label>Comments</label>
                  :<span id="votes"> </span></li>

           </ul>
     </div> 

     </apex:repeat> 
  </apex:pageBlock> 

(By the way, your getter on aggregate list is now useless, it would probably be better to put it in a new method)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.