• Hieu Vuong
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
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

Apex 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:
<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:

User-added image
 
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
 
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:

User-added image
 
Hi, 

I need help combining two list and show it on a table in SalesForce. 

Below is my apex controller class and my apex page and screenshot of my visual force page. 

Apex controller 
class 
 
public with sharing class IITDeanDashBoardController {
   public List<AggregateResult> BadgeList {
       get
       {
           List<AggregateResult> badges= [
                SELECT TargetX_SRMb__College__c
                , Department__c
                , IIT_Program__r.Name ccc
                   , count(Id) bbb
                FROM TargetX_SRMb__Application__c
                WHERE TargetX_SRMb__College__c = 'Chicago-Kent College of Law' 
                   And TargetX_SRMb__Start_Term_Year__c = '2019'
                And TargetX_SRMb__Start_Term__c = 'Fall'
                And TargetX_SRMb__Level__c = 'Graduate'
                   And TargetX_App__Is_Test_Record__c = False
                And TargetX_SRMb__Application_Submit_Date__c != Null 
                GROUP BY IIT_Program__r.Name, Department__c, TargetX_SRMb__College__c
                Order By IIT_Program__r.Name
            ];     
           return badges;
       }
       set;       
    }
    
   public List<AggregateResult> InQueueDecision {
       get
       {
           List<AggregateResult> QueueDecisions= [
                SELECT IIT_Program__r.Name ccc,
                count(Id) InDecision
                FROM TargetX_SRMb__Application__c
                WHERE TargetX_SRMb__College__c = 'Chicago-Kent College of Law' 
                   And TargetX_SRMb__Start_Term_Year__c = '2019'
                And TargetX_SRMb__Start_Term__c = 'Fall'
                And TargetX_SRMb__Level__c = 'Graduate'
                   And TargetX_App__Is_Test_Record__c = False
                And TargetX_SRMb__Application_Submit_Date__c != Null 
                And IIT_Sent_For_Faculty_Decision__c = Null
                And TargetX_SRMb__Application_Decision__c = Null
                GROUP BY IIT_Program__r.Name, Department__c, TargetX_SRMb__College__c
            ];                 
           return QueueDecisions;
       }
       set;       
    }
     
}

Apex Visual Force Page
<apex:page controller="IITDeanDashBoardController" >
    <apex:pageBlock >
        <apex:pageBlockTable value="{!BadgeList}" var="a" title="My Badges" columns="4" align="center"  styleClass="table table-striped">
            <apex:facet name="header">Chicago-Kent College of Law DashBoard </apex:facet> 
            <apex:column > 
            <apex:facet name="header">College</apex:facet>
            {!a['TargetX_SRMb__College__c']}</apex:column>
            <apex:column > <apex:facet name="header">Department</apex:facet>
            {!a['Department__c']}</apex:column>
             <apex:column > <apex:facet name="header">Program</apex:facet>
            {!a['ccc']}</apex:column>
             <apex:column > <apex:facet name="header">Total Apps</apex:facet>
            {!a['bbb']}</apex:column>
        </apex:pageBlockTable>
      </apex:pageBlock>    
    
    
        <apex:pageBlock >
        <apex:pageBlockTable value="{!InQueueDecision}" var="n" title="InqueueProcess" columns="4" align="center"  styleClass="table table-striped">
            <apex:facet name="header">Chicago-Kent College of Law DashBoard </apex:facet> 
            <apex:column > 
            <apex:facet name="header">Program</apex:facet>
            {!n['ccc']}</apex:column>
            <apex:column > <apex:facet name="header">Number of app status InProcess</apex:facet>
            {!n['InDecision']}</apex:column>
        </apex:pageBlockTable>
      </apex:pageBlock>   
  </apex:page>

Actual Page looks
User-added image 



 
Hi, 

I need help combining two list and show it on a table in SalesForce. 

Below is my apex controller class and my apex page and screenshot of my visual force page. 

Apex controller 
class 
 
public with sharing class IITDeanDashBoardController {
   public List<AggregateResult> BadgeList {
       get
       {
           List<AggregateResult> badges= [
                SELECT TargetX_SRMb__College__c
                , Department__c
                , IIT_Program__r.Name ccc
                   , count(Id) bbb
                FROM TargetX_SRMb__Application__c
                WHERE TargetX_SRMb__College__c = 'Chicago-Kent College of Law' 
                   And TargetX_SRMb__Start_Term_Year__c = '2019'
                And TargetX_SRMb__Start_Term__c = 'Fall'
                And TargetX_SRMb__Level__c = 'Graduate'
                   And TargetX_App__Is_Test_Record__c = False
                And TargetX_SRMb__Application_Submit_Date__c != Null 
                GROUP BY IIT_Program__r.Name, Department__c, TargetX_SRMb__College__c
                Order By IIT_Program__r.Name
            ];     
           return badges;
       }
       set;       
    }
    
   public List<AggregateResult> InQueueDecision {
       get
       {
           List<AggregateResult> QueueDecisions= [
                SELECT IIT_Program__r.Name ccc,
                count(Id) InDecision
                FROM TargetX_SRMb__Application__c
                WHERE TargetX_SRMb__College__c = 'Chicago-Kent College of Law' 
                   And TargetX_SRMb__Start_Term_Year__c = '2019'
                And TargetX_SRMb__Start_Term__c = 'Fall'
                And TargetX_SRMb__Level__c = 'Graduate'
                   And TargetX_App__Is_Test_Record__c = False
                And TargetX_SRMb__Application_Submit_Date__c != Null 
                And IIT_Sent_For_Faculty_Decision__c = Null
                And TargetX_SRMb__Application_Decision__c = Null
                GROUP BY IIT_Program__r.Name, Department__c, TargetX_SRMb__College__c
            ];                 
           return QueueDecisions;
       }
       set;       
    }
     
}

Apex Visual Force Page
<apex:page controller="IITDeanDashBoardController" >
    <apex:pageBlock >
        <apex:pageBlockTable value="{!BadgeList}" var="a" title="My Badges" columns="4" align="center"  styleClass="table table-striped">
            <apex:facet name="header">Chicago-Kent College of Law DashBoard </apex:facet> 
            <apex:column > 
            <apex:facet name="header">College</apex:facet>
            {!a['TargetX_SRMb__College__c']}</apex:column>
            <apex:column > <apex:facet name="header">Department</apex:facet>
            {!a['Department__c']}</apex:column>
             <apex:column > <apex:facet name="header">Program</apex:facet>
            {!a['ccc']}</apex:column>
             <apex:column > <apex:facet name="header">Total Apps</apex:facet>
            {!a['bbb']}</apex:column>
        </apex:pageBlockTable>
      </apex:pageBlock>    
    
    
        <apex:pageBlock >
        <apex:pageBlockTable value="{!InQueueDecision}" var="n" title="InqueueProcess" columns="4" align="center"  styleClass="table table-striped">
            <apex:facet name="header">Chicago-Kent College of Law DashBoard </apex:facet> 
            <apex:column > 
            <apex:facet name="header">Program</apex:facet>
            {!n['ccc']}</apex:column>
            <apex:column > <apex:facet name="header">Number of app status InProcess</apex:facet>
            {!n['InDecision']}</apex:column>
        </apex:pageBlockTable>
      </apex:pageBlock>   
  </apex:page>

Actual Page looks
User-added image