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
Francisco Garcia 34Francisco Garcia 34 

How can I pass the a number obtained in Apex and display it in Visualforce?

I need to pass a number from my Apex Class into my visualforce page.

This is my Apex Class:
public class controllerClass {
    Public Case myCase {get; set;} 
    public List<Case> cases {get; set;}    
    
    List<Case> openedCases = [SELECT AccountId, Status, Subject FROM Case WHERE IsClosed = False ORDER BY AccountId DESC];
    
    Public controllerClass(ApexPages.StandardController stdController){        
        this.myCase = (Case)stdController.getRecord();        
        this.cases = openedCases;     
    }	
    
	//This is the integer I want to pass into visualforce
	Integer temp = openedCases.size();
	
    
}

This is my Visualforce page:
 
<apex:page standardController="Case" extensions="controllerClass"> 
    
    <apex:pageBlock title="Table of Open Cases">
        <apex:pageBlockTable value="{!Cases}" var="c">
            <apex:column value="{!c.AccountId}"/>
            <apex:column value="{!c.Status}"/>
            <apex:column value="{!c.Subject}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
    
    <!-- Variable should go below-->
    <apex:variable var="" value="" />
    <p>The number from apex is <!-- Apex Number -->.</p>

        
</apex:page>

 
Best Answer chosen by Francisco Garcia 34
Nayana KNayana K
<apex:page standardController="Case" extensions="controllerClass"> 
    
    <apex:pageBlock title="Table of Open Cases">
        <apex:pageBlockTable value="{!Cases}" var="c">
            <apex:column value="{!c.AccountId}"/>
            <apex:column value="{!c.Status}"/>
            <apex:column value="{!c.Subject}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
    
    <!-- Variable should go below-->
    <apex:variable var="" value="" />
    <p>The number from apex is {!cases.size}.</p>

        
</apex:page>

Instead of that integer you can directly get the size like above.


If you want to use integer number then:
 
public class controllerClass {
    Public Case myCase {get; set;} 
    public List<Case> cases {get; set;}    
    
    List<Case> openedCases = [SELECT AccountId, Status, Subject FROM Case WHERE IsClosed = False ORDER BY AccountId DESC];
    
    Public controllerClass(ApexPages.StandardController stdController){        
        this.myCase = (Case)stdController.getRecord();        
        this.cases = openedCases;    
    }	
    public Integer temp
{ get{return openedCases.size();}
set;}
	
	
    
}

Use this temp in page. 

All Answers

Nayana KNayana K
<apex:page standardController="Case" extensions="controllerClass"> 
    
    <apex:pageBlock title="Table of Open Cases">
        <apex:pageBlockTable value="{!Cases}" var="c">
            <apex:column value="{!c.AccountId}"/>
            <apex:column value="{!c.Status}"/>
            <apex:column value="{!c.Subject}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
    
    <!-- Variable should go below-->
    <apex:variable var="" value="" />
    <p>The number from apex is {!cases.size}.</p>

        
</apex:page>

Instead of that integer you can directly get the size like above.


If you want to use integer number then:
 
public class controllerClass {
    Public Case myCase {get; set;} 
    public List<Case> cases {get; set;}    
    
    List<Case> openedCases = [SELECT AccountId, Status, Subject FROM Case WHERE IsClosed = False ORDER BY AccountId DESC];
    
    Public controllerClass(ApexPages.StandardController stdController){        
        this.myCase = (Case)stdController.getRecord();        
        this.cases = openedCases;    
    }	
    public Integer temp
{ get{return openedCases.size();}
set;}
	
	
    
}

Use this temp in page. 
This was selected as the best answer
Francisco Garcia 34Francisco Garcia 34
Thanks! But I just used the size of openedCases as an example. How would I transfer say a hardcoded number? I want to know for every situation, not just this one example.
Hemant_SoniHemant_Soni
Hi Francisco,
If you need hardcoded value in you vf page then assign value in constructor.Try like below code
public class controllerClass {
    Public Case myCase {get; set;} 
    public List<Case> cases {get; set;}    
    public integer temp{get;set;}
    List<Case> openedCases = [SELECT AccountId, Status, Subject FROM Case WHERE IsClosed = False ORDER BY AccountId DESC];
    
    Public controllerClass(ApexPages.StandardController stdController){        
        this.myCase = (Case)stdController.getRecord();        
        this.cases = openedCases;     
    }	

  public controllerClass(){
		temp = HARDCODED NUMBER;
		}  
}
If you need dynamic then @Nayana K is right.
Please mark it solved.
Thanks
Hemant

 
Francisco Garcia 34Francisco Garcia 34
Alright! Thanks for the reply!