How to implement pagination in Visualforce with Example?

This is one of the most common interview question which employers love to ask. In this blog post, we will see how to implement pagination in Visualforce. I hope you will enjoy this blog post. Please share your feedback in the comment section.

What is Pagination in Visualforce?
Pagination is the process of displaying large number of records and displaying the records on multiple pages within in Salesforce.

In order to control the number of records displayed on each page, we use pagination. By default, a list controller returns 20 records on the page.

To customize it, we can use a controller extension to set theĀ pageSize. Take a look at the sample code below:-

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


By default it will show 20 records on a page, if you want to change the number of records to display on each page, you can use pageSize method as show below:

public class oppoNe {

    public oppoNe(ApexPages.StandardSetController controller) {


In the above example,I have used the setPageSize() to set the number of records to be displayed on every page.

Here is also the link for the video related to Pagination:

This Post Has 6 Comments

  1. HI deepika.
    No link visible for pagination video??

    1. There is a video on the page here.Were you able to see the video?

  2. Hi deepika,

    when i clicked on links like first,last etc it is throwing an error that..formula expression is needed..can you look into it..

  3. Hi deepika,

    I got it..sorry I didn’t add formula expression in the links..

  4. Good one

Leave a Reply

Close Menu