
10 risposte
Hi Ramacahandran,Use a custom controller for custom object or for multi object query.I've tidied and corrected Jyothsna's code...<apex:page Controller="PaginationExampleController"> <!-- readOnly="true" contentType="application/vnd.ms-excel⌗UserReport.xls" cache="true" --><!-- https://trailhead.salesforce.com/visualforce_fundamentals/visualforce_standard_list_controllers --><!-- Pagination --><!-- https://developer.salesforce.com/forums/?id=906F0000000BZxWIAWhttps://developer.salesforce.com/forums/?id=906F000000096lRIAQ --> <apex:form id="form"> <apex:pageBlock > <apex:pageBlockTable value="{!leads}" var="ld"> <apex:column headerValue="Name"> <apex:outputField value="{!ld.Name}"/> </apex:column> <apex:column headerValue="Email"> <apex:outputField value="{!ld.Email}"/></apex:column><apex:column headerValue="Company"><apex:outputField value="{!ld.Company}"/></apex:column></apex:pageBlockTable><apex:outputLabel >Total no of recs:{!totalRecs}</apex:outputLabel><div align="center"> <apex:commandButton value="First Page" action="{!Firstbtn}" disabled="{!prv}" reRender="form"/> <apex:commandButton value="PreviousPage" action="{!prvbtn}" disabled="{!prv}" reRender="form"/> <apex:commandButton value="NextPage" action="{!Nxtbtn}" disabled="{!nxt}" reRender="form"/> <apex:commandButton value="LastPage" action="{!lstbtn}" disabled="{!nxt}" reRender="form"/> </div> Display records per page <apex:selectList value="{!numberOfRowsToReturn}" size="1" > <apex:selectOption itemLabel="1" itemValue="1" ></apex:selectOption> <apex:selectOption itemLabel="2" itemValue="2"></apex:selectOption> <apex:selectOption itemLabel="5" itemValue="5"></apex:selectOption> <apex:selectOption itemLabel="10" itemValue="10"></apex:selectOption> <apex:actionSupport event="onchange" reRender="form" action="{!updatePage}"/> </apex:selectList><br/> </apex:pageBlock> </apex:form> </apex:page> public with sharing class PaginationExampleController { public List<Lead> leads=new List<Lead>(); public integer totalRecs { get; set; } public integer numberOfRowsToReturn {get; set;} integer skipCount; //Constructor public PaginationExampleController() { numberOfRowsToReturn= 10; skipCount= 0; totalRecs = [SELECT Count() FROM Lead]; } public List<Lead> getLeads() { system.debug('numberOfRowsToReturn :' + numberOfRowsToReturn); system.debug('skipCount :' + skipCount); List<Lead> ld=[SELECT Name,Email,Company FROM Lead LIMIT:numberOfRowsToReturn OFFSET:skipCount]; system.debug('values are:' + ld); return ld; } public void updatePage() { leads.clear(); leads=[SELECT Name,Email,Company FROM Lead LIMIT:numberOfRowsToReturn OFFSET:skipCount]; } public PageReference firstBtn() { skipCount=0; return null; } public PageReference prvBtn() { skipCount=skipCount-numberOfRowsToReturn; return null; } public PageReference nxtBtn() { //skipCount cannot be > 2000 - a limitation of this method skipCount=skipCount+numberOfRowsToReturn; if (skipCount>2000){skipCount=2000;} return null; } public PageReference lstBtn() { skipCount= totalrecs - math.mod(totalRecs,numberOfRowsToReturn); if (skipCount>2000){skipCount=2000;} return null; } public Boolean getNxt() { if((skipCount+ numberOfRowsToReturn) > totalRecs) return true; else return false; } public Boolean getPrv() { if(skipCount== 0) return true; else return false; } }//PaginationExampleController