You need to sign in to do that
Don't have an account?
![Hieu Vuong Hieu Vuong](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Wrapper List not show up
I'm trying to create a table to provide metrics on the number of Account and Contact records grouped by state. So each state will have two number of count id.
Below is a code for my class and visual force page
Class
This is my visualforce page code:
Screenshot of my visualforce page showing nothing:
![User-added image](/forums/servlet/rtaImage?eid=9062I000000gB56&feoid=Body&refid=0EM2I000000gTdY)
Below is a code for my class and visual force page
Class
public with sharing class SampleController { public list<stateWrapper> recordlist { get; set;} public class stateWrapper { public String stateName; public Integer contactCount; public Integer accountCount; //Default constructor for innerClass public stateWrapper( String stateName, Integer contactCount, Integer accountCount ){ this.stateName = stateName; this.contactCount = contactCount; if ( contactCount == null ){ contactcount = 0; } this.accountCount = accountCount; if ( accountCount == null ){ accountCount = 0; } //the above this keyword denotes that we are talking about //the variables outside the constructor and not //the input parameters by the same name. } } public static Map<String,stateWrapper> calculateMetrics(){ Map<String,stateWrapper> stateMap = new Map<String,stateWrapper>(); for ( AggregateResult ar : [ Select Count(id) cnt, BillingState state from Account where BillingState != null group by BillingState ]){ stateWrapper sw = new stateWrapper( (string)ar.get('state'), (integer)ar.get('cnt'), null ); stateMap.put(sw.stateName,sw); } for ( AggregateResult ar : [ Select Count(id) cnt, MailingState state from Contact where MailingState != null group by MailingState ]){ stateWrapper sw = new stateWrapper( (string)ar.get('state'), null, null ); if ( stateMap.containsKey(sw.stateName) ){ sw = stateMap.get(sw.stateName); } sw.contactCount = (integer)ar.get('cnt'); stateMap.put(sw.stateName,sw); } return stateMap; } }
This is my visualforce page code:
<apex:page controller="SampleController" > <apex:pageBlock > <apex:pageBlockTable value="{!recordlist}" var="a" title="My Badges" columns="4" align="center" styleClass="table table-striped"> <apex:facet name="header">Account and Contact State DashBoard </apex:facet> <apex:column > <apex:facet name="header">State</apex:facet> {!a['stateName']}</apex:column> <apex:column > <apex:facet name="header">Number of Contacts</apex:facet> {!a['contactCount']}</apex:column> <apex:column > <apex:facet name="header">Number of Accounts</apex:facet> {!a['accountCount']}</apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:page>
Screenshot of my visualforce page showing nothing:
You are not filling the recordList variable . You have missed to add the wrapper in the list.
recordList.add(sw);
Hope this helps.