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
AbAb 

Pagination o, pageblocktable

Hello,

I am looking for a tutorial to implement Pagignation on table, It will return around 20000 rows.
Best Answer chosen by Ab
Amit Chaudhary 8Amit Chaudhary 8
Please check below blog. I hope that will help u
http://amitsalesforce.blogspot.in/2015/04/pagination-using-standardsetcontroller.html

Thanks
Amit Chaudhary

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please check below blog. I hope that will help u
http://amitsalesforce.blogspot.in/2015/04/pagination-using-standardsetcontroller.html

Thanks
Amit Chaudhary
This was selected as the best answer
Mubarak HussainMubarak Hussain
Hi Sandrine

VisualForce Page
<apex:page Controller="Pagination" >
 <apex:pageblock >
 <apex:pageBlockTable value="{!acc}" var="a" id="Detail">
 <apex:column value="{!a.name}"/>
 <apex:column value="{!a.website}"/>
 <apex:column value="{!a.type}"/>
 <apex:column value="{!a.description}"/>
 <apex:column value="{!a.phone}"/>
 </apex:pageBlockTable>
 <apex:form >
 <apex:commandButton value="FirstPage" action="{!firstpage}" reRender="detail" />
 <apex:commandButton value="Previous" action="{!Previous}" reRender="Detail" />
 <apex:commandButton value="Next Page" action="{!NextPage}" reRender="Detail" />
 <apex:commandButton value="Last Page" action="{!LastPage}" reRender="Detail" />
 </apex:form>
 
 </apex:pageblock>
</apex:page>
Controller
public class Pagination {


private integer totalrec=0;
private integer limitsize=10;
private integer offsetsize=0;

Public pagination(){

totalrec= [select count() from Account];
}

    public list< Account> getAcc() {
    
   list<Account>acc=new list<Account>();
   acc=database.query('Select name,Website,type,description,phone from Account limit :limitsize Offset :OffsetSize ');
   system.debug('Values are'+acc);
    return acc;
    }
    public void firstPage(){
    
   offsetsize=0;
    }
    
        
    public void previous(){
    
    offsetsize=offsetsize-limitsize;
        }    
     public void nextpage(){
     offsetsize=offsetsize+limitsize;
     
     }   
      public void lastpage(){
      
      if(math.mod(totalrec,limitsize)==0)
      offsetsize=totalrec-limitsize;
      else
      offsetsize=totalrec-math.mod(totalrec,limitsize);
      
      }  
      public boolean getprev(){
      if(offsetsize==0)
      return true;
      else
      return false;
            }  
      public boolean getnxt(){
      if((offsetsize+limitsize)>totalrec)
      return true;
      else
      return false;
      }
      }

Hope this will help you.

Thanks
Muba