I'm trying out Pagination and I have a weird problem :

Whenever the total number of my input in multiple's of 10's (eg, 10, 30, 100 etc, and its 40 in current problem), the pagination will give me an EXTRA page.

Say I want to show 10 records/results per "pagination page", it will display the first 40 perfectly. 1-10 (page 1 of 4), 11-20 (page 1 of 4), 21-30 (page 1 of 4), 31-40 (page 1 of 4).

It will ALSO display an empty page (page 5 of 4).

VF page


I am unable to find the cause of this "problem".

Any help in pinning down the cause would be HIGHLY appreciated.

  • In the one case you're doing integer i=1;<41;i++. In another place you're starting with counter = 0 and adjusting for it by adding 1 to your code elsewhere. Be consistent. I think this is the source of your issue. Use i=0;<40;i++ and account for the same adjustments everywhere.
    – crmprogdev
    Jul 15, 2016 at 12:28

1 Answer 1


Problem is in your end button reference.

counter = total_size - math.mod(total_size, list_size); 

which is ok for non multiples of 10. for multiples of 10 this should be:

counter = total_size - list_size;

Otherwise your next page will start from a counter of (in this example) 40 and create an empty page. try the following:

if(math.mod(total_size, list_size) == 0){
   counter = total_size - list_size;
   counter = total_size - math.mod(total_size, list_size);
  • Can you add a little more explanation for why the one approach is wrong and your recommendation is correct? Or how you can make them both fit together if that's necessary?
    – Adrian Larson
    Jul 15, 2016 at 13:21
  • Just PERFECT. Thank you, I understand now what was wrong, passing the original counter the old way was artificially "expanding" the page numbers. I love answers like yours, everything just "clicks" into place leading to an "AHA!" moment!
    – fraglord
    Jul 18, 2016 at 8:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .