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
Dave BerenatoDave Berenato 

Display Count Variables in Visualforce Page

I'm trying to write a visualforce page that displays variables from an Apex Class in a table.

Here's the Apex Class
 
public class SettersTestController {
    
    public list <Task> ListCallAry
    Integer CallAry =  [SELECT count()  
                                            FROM Task  
                                            WHERE skyplatform__Is_Call_Record__c = TRUE
                                            And CreatedDate = THIS_MONTH
                                            And CreatedBy = '0056A000001IVgU'];
    
    public list <Event> ListSetAry
    Integer SetAry =  [SELECT count()  
                                            FROM Event  
                                            WHERE RecordTypeId = '0126A0000004Qle'
                                            And CreatedDate = THIS_MONTH
                                            And Appoint_Set_By__c = '0056A000001IVgU'];
    
    public list <Event> ListShownAry
    Integer ShownAry =  [SELECT count()  
                                            FROM Event  
                                            WHERE RecordTypeId = '0126A0000004Qle'
                                            And Type = 'Appointment - Shown'
                                            And ActivityDateTime = THIS_MONTH
                                            And Appoint_Set_By__c = '0056A000001IVgU'];
​}

And then the Visualforce Page:

<apex:page Controller="SettersTestController">
<apex:pageBlock title="Test">
    <apex:pageBlockSection>
        <table>
            <tr>
            	<th>Name</th>
            	<th>Calls</th>
            	<th>Set</th>
            	<th>Shown</th>
            </tr>
            <tr>
          		<td>Ary</td>
        		<td><apex:outputField value="{!Task.ListCallAry}"/></td>
                        <td><apex:outputField value="{!Event.ListSetAry}"/></td>
                        <td><apex:outputField value="{!Event.ListShownAry}"/></td>
            </tr>
        </table>
    </apex:pageBlockSection>
</apex:pageBlock>
</apex:page>

The error message is "Unexpected Token: Integer"
Best Answer chosen by Dave Berenato
Nithesh NNithesh N
This Should do the Trick, this will display the Count of Accounts and Events in the Visualforce Page.
<apex:page Controller="countController">
<apex:pageBlock title="Test">
    <apex:pageBlockSection>
        <table>
            <tr>
            	<th>Name</th>
            	<th>Calls</th>
                <th>Set</th>
                <th>Shown</th>
            </tr>
            <tr>
        		<td>Ary</td>
                <td>{!Calls}</td>
                <td>{!EventsSet}</td>
                <td>{!EventsShown}</td>
            </tr>
        </table>
    </apex:pageBlockSection>
</apex:pageBlock>
</apex:page>

Controller:
 
public class countController {
    public Integer getCalls(){        
        return (Integer) [SELECT count()  
                                            FROM Task  
                                            WHERE skyplatform__Is_Call_Record__c = TRUE
                                            And CreatedDate = THIS_MONTH
                                            And CreatedBy = '0056A000001IVgU' ];
    } 
    
      public Integer getEventsSet(){        
        return (Integer) [SELECT count()  
                                            FROM Event  
                                            WHERE RecordTypeId = '0126A0000004Qle'
                                            And CreatedDate = THIS_MONTH
                                            And Appoint_Set_By__c = '0056A000001IVgU'];
    } 

       public Integer getEventsShown(){        
        return (Integer) [SELECT count()  
                                            FROM Event  
                                            WHERE RecordTypeId = '0126A0000004Qle'
                                            And Type = 'Appointment - Shown'
                                            And ActivityDateTime = THIS_MONTH
                                            And Appoint_Set_By__c = '0056A000001IVgU'];
    } 
    
    
}

Please do not forget to mark this thread as SOLVED and answer as the BEST ANSWER if it helps address your issue.

Best,
Nithesh
 

All Answers

Nithesh NNithesh N
This Should do the Trick, this will display the Count of Accounts and Events in the Visualforce Page.
<apex:page Controller="countController">
<apex:pageBlock title="Test">
    <apex:pageBlockSection>
        <table>
            <tr>
            	<th>Name</th>
            	<th>Calls</th>
                <th>Set</th>
                <th>Shown</th>
            </tr>
            <tr>
        		<td>Ary</td>
                <td>{!Calls}</td>
                <td>{!EventsSet}</td>
                <td>{!EventsShown}</td>
            </tr>
        </table>
    </apex:pageBlockSection>
</apex:pageBlock>
</apex:page>

Controller:
 
public class countController {
    public Integer getCalls(){        
        return (Integer) [SELECT count()  
                                            FROM Task  
                                            WHERE skyplatform__Is_Call_Record__c = TRUE
                                            And CreatedDate = THIS_MONTH
                                            And CreatedBy = '0056A000001IVgU' ];
    } 
    
      public Integer getEventsSet(){        
        return (Integer) [SELECT count()  
                                            FROM Event  
                                            WHERE RecordTypeId = '0126A0000004Qle'
                                            And CreatedDate = THIS_MONTH
                                            And Appoint_Set_By__c = '0056A000001IVgU'];
    } 

       public Integer getEventsShown(){        
        return (Integer) [SELECT count()  
                                            FROM Event  
                                            WHERE RecordTypeId = '0126A0000004Qle'
                                            And Type = 'Appointment - Shown'
                                            And ActivityDateTime = THIS_MONTH
                                            And Appoint_Set_By__c = '0056A000001IVgU'];
    } 
    
    
}

Please do not forget to mark this thread as SOLVED and answer as the BEST ANSWER if it helps address your issue.

Best,
Nithesh
 
This was selected as the best answer
Dave BerenatoDave Berenato
Worked perfectly. Thank you!