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

[sourcecode lang=”Java”]

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

[sourcecode lang=”Java”]
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:
[s3video s3url=”/SalesforceInterviewCourse/tutorial35PaginationWithExample.mp4″ responsive=”on” /]

This Post Has 16 Comments

  1. Frederick

    HI deepika.
    No link visible for pagination video??

    1. MyTutorialRack

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

  2. Ehsna

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

    Hi deepika,

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

  4. C

    Good one

  5. berkey

    Wow that was odd. I just wrote an incredibly long comment but after I clicked submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Anyhow, just wanted to say superb blog!|

  6. camo cases

    Hello there, just became alert to your blog through Google, and found that it’s truly informative. I am gonna watch out for brussels. I will appreciate if you continue this in future. Numerous people will be benefited from your writing. Cheers!|

  7. the feed

    I would like to thank you for the efforts you have put in penning this website. I really hope to check out the same high-grade content by you later on as well. In truth, your creative writing abilities has inspired me to get my own blog now ;)|

  8. the feed

    What a information of un-ambiguity and preserveness of precious familiarity about unpredicted feelings.|

  9. thefeed

    Good blog you have here.. It’s hard to find high quality writing like yours nowadays. I really appreciate people like you! Take care!!|

  10. feed

    You really make it seem so easy with your presentation but I find this topic to be really something that I think I would never understand. It seems too complex and very broad for me. I am looking forward for your next post, I’ll try to get the hang of it!|

  11. feed

    I absolutely love your blog and find most of your post’s to be what precisely I’m looking for. Does one offer guest writers to write content to suit your needs? I wouldn’t mind creating a post or elaborating on most of the subjects you write related to here. Again, awesome web site!|

  12. zortilo nrel

    Whats up very nice blog!! Man .. Beautiful .. Wonderful .. I’ll bookmark your web site and take the feeds additionallyKI’m glad to find numerous useful information here in the post, we’d like develop more techniques in this regard, thanks for sharing. . . . . .

  13. froleprotrem

    Hello there, just became alert to your blog through Google, and found that it’s really informative. I’m gonna watch out for brussels. I will be grateful if you continue this in future. Lots of people will be benefited from your writing. Cheers!

Leave a Reply