How to include number of records in button name in Visualforce Page?

How to include number of records in button name in Visualforce Page?

Sample Code:


Visualforce page:

<apex:page controller=”SampleController”>
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockTable value=”{!empList}” var=”e”>
            <apex:column value=”{!e.Name}”/>
        </apex:pageBlockTable>
        <apex:pageBlockButtons >            
            <apex:commandButton value=”Convert All {!empCount} Records”/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
</apex:form>
</apex:page>

Apex Controller:

public class SampleController {
    public List<Employee__c> empList {get;set;}
    public Integer empCount {get;set;}
    public SampleController() {
        empList = [SELECT Id, Name FROM Employee__c];
        empCount = empList.size();
    }
}


Output:



Leave a Reply