Overriding Default Size 20 of Standard List Controller While Pagination


// Override default size 20 to 2 as below.
If you want to overide the record per page then you will have to use custom controller for Sales__c object as below. In the below custom controller, i have set page size =2 so that you can see the effects of pagination.

----------------VF------------------------------------
<apex:page controller="CustomObjectPaginationController">
     <apex:form >
        <apex:pageBlock >
           <apex:pageMessages />
         
            <apex:pageBlockButtons >
               <apex:commandButton value="Save" action="{!setCon.save}"/>
               <apex:commandButton value="Return" action="{!setCon.cancel}"/>
            </apex:pageBlockButtons>
         
            <apex:pageBlockTable value="{!customObjects}" var="s" id="table" rows="10">
                <apex:column headerValue="Account Name">
                  <apex:outputField value="{!s.Name}"/>
                   </apex:column>
            </apex:pageBlockTable>
         
           <apex:commandLink action="{!setCon.previous}" value="Previous Page" rendered="{!setCon.hasPrevious}"/>&nbsp;
           <apex:commandLink action="{!setCon.next}" value="Next Page" rendered="{!setCon.hasNext}"/>&nbsp;
           <apex:commandLink action="{!setCon.last}" value="Last Page" rendered="{!setCon.hasNext}"/>&nbsp;
           <apex:commandLink action="{!setCon.first}" value="First Page" rendered="{!setCon.hasPrevious}"/>
         
         </apex:pageBlock>
      </apex:form>
 </apex:page>
---------------------------------

Controller
----------------------------------
public class CustomObjectPaginationController{
public Integer size{get;set;}
    public CustomObjectPaginationController(){
        size=2;
    }
   
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {              
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [select id,Name from sale__c]));
                setCon.setPageSize(size);
            }          
            return setCon;
        }
        set;
    }
   
    // Initialize setCon and return a list of record  
    public List<sale__cgetCustomObjects() {
         return (List<sale__c>) setCon.getRecords();
    }
}
---------------------------------------------------------------

I hope this will help you.

Comments

Popular posts from this blog

System.AsyncException: The Apex job named is already scheduled for execution.

Custom Setting Creation in Apex Test Class

Error : "Trigger must be associated with a job detail"

AJAX Toolkit Debug Shell

Salesforce Trace Log Query Using Apex

how to get object name from id / prefix value in salesforce

How to Query All the batch classes in your Salesforce Instance using APEX

Creating Salesforce Developer Account

Creating MAP from SOQL Query

Custom Pagination Without Controller (Apex)