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
Jackson DiasJackson Dias 

pagination in vf

what is pagination in vf ? how do I implement it with an example. Thanks
SandhyaSandhya (Salesforce Developers) 
Hi Jackson Dias,
Usually, Salesforce shows by default 25 records at a time when you want to display 10records at a time we need to make use of Previous, next and last buttons in the Visual force page this itself is pagination.

Please refer below example how we can achieve this.
<apex:page standardController="Account" <b>recordSetvar="accounts"</b>>
<apex:pageBlock title="ViewingAccounts">
<apex:form id="theForm">
<apex:dataList var="a" value="{!accounts}" type="1">
<apex:panelGrid columns="2">
<apex:commandLink action="<b>{!previous}</b>">Previous</apex:commandlink>
<apex:commandLink action="<b>{!next}</b>">Next</apex:commandlink>
public class tenPageSizeExt {
public tenPageSizeExt(ApexPages.StandardSetControllercontroller){
Also, refer below link for one more example .

Hope this helps you!

Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
Thanks and Regards

Rupal KumarRupal Kumar
As the number of records increases on the vf page Select value of number of record like you want to display only 10,20,30 and 40... record on vf page with Next  and Privous button its pagination.


Vf page-
<apex:page controller="Pagination_minnew">
    <apex:form >
        <apex:pageBlock id="pb">
            <apex:pageBlockTable value="{!Accounts}" var="a">
              <apex:column >
                    <apex:facet name="header">Action</apex:facet>
                    <apex:inputCheckbox />
                <apex:column value="{!a.Name}"/>
                <apex:column value="{!a.Type}"/>
                <apex:column value="{!a.BillingCity}"/>
                <apex:column value="{!a.BillingState}"/>
                <apex:column value="{!a.BillingCountry}"/>
            <apex:panelGrid columns="7">
                <apex:commandButton status="fetchStatus" reRender="pb" value="|<" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value="Next" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!}" disabled="{!!setCon.hasNext}" title="Next Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value=">|" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/>
                <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,(setCon.pageNumber * size))} of {!noOfRecords}</apex:outputText>
                <apex:commandButton status="fetchStatus" reRender="pb" value="Refresh" action="{!refresh}" title="Refresh Page"/>
                <apex:actionFunction name="show" action="{!refresh}" reRender="pb" />
                <apex:selectList value="{!size}"  multiselect="false" size="1" onchange="show()">
                      <apex:selectOptions value="{!items}"/>
                <apex:outputPanel style="color:#4AA02C;font-weight:bold">
                    <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>

public with sharing class Pagination_minnew {
    Public Integer noOfRecords{get; set;}
    Public Integer size{get;set;}
    public boolean test = false;
    public ApexPages.StandardSetController setCon {
            if(setCon == null){
                if(test == false){
                size = 10;
                string queryString = 'Select Name, Type, BillingCity, BillingState, BillingCountry from Account order by Createddate DESC';
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
                noOfRecords = setCon.getResultSize();
                test = true;
            return setCon;
    Public List<Account> getAccounts(){
        List<Account> accList = new List<Account>();
        for(Account a : (List<Account>)setCon.getRecords())
        return accList;
    public pageReference refresh() {
        setCon = null;
        return null;
    public List<SelectOption> getItems() {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('10','10'));
            options.add(new SelectOption('20','20'));
            options.add(new SelectOption('30','30'));
              options.add(new SelectOption('40','40'));
            return options;

Rupal Kumar
Deepali KulshresthaDeepali Kulshrestha
Hi Jackson,

Pagination is the process of displaying a large number of records and displaying the records on multiple pages within in Salesforce
<apex:page standardController="Opportunity" extensions="oppoNe" recordSetVar="opportunities">
<apex:pageBlock title="Viewing Opportunities">
<apex:form id="theForm">
<apex:pageBlockSection >
<apex:dataList var="opp" value="{!opportunities}">
<apex:panelGrid columns="4">
<apex:commandLink action="{!first}">FIRST</apex:commandLink>
<apex:commandLink action="{!next}">NEXT</apex:commandLink>
<apex:commandLink action="{!previous}">PREVIOUS</apex:commandLink>
<apex:commandLink action="{!last}">LAST</apex:commandLink>


public class oppoNe {
    public oppoNe(ApexPages.StandardSetController controller) {
I suggest you visit this link, it will help you

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,

Deepali Kulshrestha.

Suraj Tripathi 47Suraj Tripathi 47
Hi Jackson Dias,
You can take reference from below code for the pagination.
//Vf Page
<apex:page controller="Pagination" sidebar="false" showHeader="false">
    <apex:form >
        <apex:pageBlock id="details">
            <apex:pageblockTable value="{!acclist}" var="con">
                <apex:column value="{!con.FirstName}"/>
                <apex:column value="{!con.LastName}"/>
                <apex:column value="{!con.Email}"/>
                <apex:column value="{!con.Phone}"/>
            <apex:pageblockButtons >
                <apex:commandButton action="{!FirstPage}" value="Page" />
                <apex:commandButton value="Previous" rerender="details" action="{!previous}" disabled="{!prev}"/>
                <apex:commandButton value="Next" rerender="details" action="{!next}" disabled="{!nxt}"/>

public class Pagination
    List<Contact> contactList=[SELECT FirstName,LastName,Email,Phone FROM Contact LIMIT 10000];
    private integer totalRecs = contactList.size();
    public integer OffsetSize = 0;
    private integer LimitSize= 10;

    public List<Contact> getacclist()
        List<Contact> con = Database.Query('SELECT FirstName, LastName, Email, Phone FROM Contact LIMIT :LimitSize OFFSET :OffsetSize');
        System.debug('Values are' + con);
        return con;
    public void FirstPage()
        OffsetSize = 0;
    public void previous()
        OffsetSize = OffsetSize - LimitSize;
    }public void next()
        OffsetSize = OffsetSize + LimitSize;
    }public void LastPage()
        OffsetSize = totalrecs - math.mod(totalRecs,LimitSize);
    public boolean getprev()
        if(OffsetSize == 0)
            return true;
            return false;
    public boolean getnxt()
        if((OffsetSize + LimitSize) > totalRecs)
            return true;
            return false;

If you find your Solution then mark this as the best answer.

Thank you!

Suraj Tripathi