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
SFDC TortoiseSFDC Tortoise 

I want to achieve pagination for custom object using wrapper class. How can i achieve?

Khan AnasKhan Anas (Salesforce Developers) 
Hi Sonu,

Greetings to you!

Please refer to the below links which might help you further with the above requirement (you can use a custom object instead of a standard object).

http://www.sfdcpoint.com/salesforce/pagination-using-standardsetcontroller-with-wrapper-class/

http://www.sfdcsharepoint.com/wrapper-class-pagination-salesforce/

http://amitsalesforce.blogspot.com/2014/11/pagination-with-wrapper-class-with.html

https://programsinengineering.blogspot.com/2018/04/visualforce-page-with-wrapper-class.html

https://www.mstsolutions.com/technical/pagination-in-salesforce-with-maintaining-selected-records/

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
SFDC TortoiseSFDC Tortoise

hello sir,

I am achive pagination using StandardSetController. By following way

my VF is ,,


<apex:page sidebar="false" Controller="practiceClaimcontinueApex" >
    <apex:form >
        <apex:pageblock id="pageBlock"  rendered="{!flag1==true}">
            <apex:pageBlockButtons location="both">
                <apex:commandButton value="Claim Properties" action="{!claimProperties}"/>
                <apex:commandButton value="Claim & Continue" action="{!Claim_continue}" />
                <apex:commandButton value="Cancel" action="{!Cancel}" />        
            </apex:pageBlockButtons>             
             <apex:pageBlock id="page">
              <apex:pageblockTable value="{!wraplist}" var="a" >
                <apex:column >
                    <apex:inputCheckbox value="{!a.selectedItem}" />
                </apex:column>
                <apex:column value="{!a.wrapPro.Property_Name__c}"/>
                <apex:column value="{!a.wrapPro.Property_City__c}"/>
                <apex:column value="{!a.wrapPro.Listing_Price__c}"/>
                <apex:column value="{!a.wrapPro.Status__c }"/>
            </apex:pageblockTable>
            </apex:pageBlock>             
            <apex:commandButton status="fetchStatus" reRender="pageBlock" value="First" action="{!first}" title="First Page" />
           <apex:commandButton status="fetchStatus" reRender="pageBlock" value="Previous" action="{!previous}" title="Previous Page" />
           <apex:commandButton status="fetchStatus" reRender="pageBlock" value="Next" action="{!next}" title="Next Page" />
           <apex:commandButton status="fetchStatus" reRender="pageBlock" value="Last" action="{!last}" title="Last Page" />
          <apex:outputText >{!(setController.pageNumber * size)+1-size}-{!IF((setController.pageNumber * size)>noOfRecords, noOfRecords,
                   (setController.pageNumber * size))} of {!noOfRecords}
              </apex:outputText>
              <apex:outputPanel >
              <apex:actionStatus id="fetchStatus" startText="Fetching....">
              </apex:actionStatus>
              </apex:outputPanel>                                     
        </apex:pageblock>         
        <apex:pageBlock title="Selected Property" rendered="{!flag2==true}">
            <apex:pageBlockTable value="{!selectedMenuItemList}" var="b">
                <apex:column value="{!b.wrapPro.Property_Name__c}"/>
                <apex:column value="{!b.wrapPro.Property_City__c}"/>
                <apex:column value="{!b.wrapPro.Listing_Price__c}"/>
                <apex:column value="{!b.wrapPro.Status__c }"/>      
            </apex:pageBlockTable>
        </apex:pageBlock>       
    </apex:form>
</apex:page>
 Apex Class is,
public class practiceClaimcontinueApex {

    public String first { get; set; }

    Public List<WrapperProperty> wraplist{set;get;}
    public List<WrapperProperty> selectedMenuItemList{set;get;}
    public boolean flag1{get;set;}
    public boolean flag2{get;set;}
    Public Integer size{get;set;}
    public Integer noOfRecords{get;set;}
    public ApexPages.StandardSetController setController{
    get{
    if(setController==null){
    setController = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT ID,Property_Name__c  ,Property_City__c,Listing_Price__c,Status__c FROM  Property__c WHERE Status__c = 'open']));
    setController.setPageSize(size);
    noOfRecords = setController.getResultSize();
    }
    return setController;
    }
        set;}
   

    public practiceClaimcontinueApex(){
        size = 5;
        flag1=true;
        flag2=false;
        wraplist = new List<WrapperProperty>();
        List<Property__c> mainList = [SELECT ID,Property_Name__c  ,Property_City__c,Listing_Price__c,Status__c FROM  Property__c WHERE Status__c = 'open' LIMIT 5];
        for(Property__c forPor :mainList ){
            wraplist.add(new WrapperProperty(forPor));
        }
    }
    //Public List<WrapperProperty>
    public List<Property__c> getOpportunities(){
    return (List<Property__c>) setController.getRecords();
   }

   
    public PageReference claimProperties(){
        PageReference pageRef = new PageReference('https://ap15.salesforce.com/a01/o');
        pageRef.setRedirect(true);
        return pageRef;     
       
    }
   
    public void Claim_continue(){
        flag1=false;
        flag2=true; 
        selectedMenuItemList = new List<WrapperProperty>();
        for(WrapperProperty eachwrap : wraplist){
            if(eachwrap.selectedItem==true){
                selectedMenuItemList.add(eachwrap);
            }
        }
But my list is not changing when i click on button. What is wrong in that can you plz help me.

I atteched the screen short
slecting on first page
User-added image