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
SoundarSoundar 

Pagination is Not Working In Wrapper Class

Hi Expect,

Could You Please advise me ! Why pagination is not working in wrapper class. I tried seperately (pagination & wrapper) as well, it's working in sepetaetly but not working when i include pagination with wrapper.

*********Apex Class ************
public class OpportunityListWithWrapperClass {
   
    //Variables for Wrapper
    public List<wrapperClass> wrapperList{get;set;}
    public boolean normalList{get;set;}
    public boolean selectedList{get;set;}
    Public List<WrapperClass> SelectedWrapperList{get;set;} 
    
    //Variable For Pagination
    public Integer size{get;set;}
    public Integer noOfRecords{get;set;}
    Public List<SelectOption> paginationSizeFixing{get;set;}
    
     //Constructor 
    public OpportunityListWithWrapperClass(){
        normalList = True;
        selectedList = False;
    	selectOpp(); 
        size=5;
        
        paginationSizeFixing = New List<selectOption>();
        paginationSizeFixing.add(New selectOption('5','5'));
        paginationSizeFixing.add(New selectOption('10', '10'));
        paginationSizeFixing.add(New selectOption('20', '20'));
        paginationSizeFixing.add(New selectOption('30', '30'));
    }
    
    
    //Method For Pagination for Wrapper
    Public Apexpages.StandardSetController setCon{
        
        get{if(setCon == Null){
            
            setCon = New ApexPages.StandardSetController(database.getQueryLocator([select Id,name,accountId,account.name,stageName,Amount,closeDate
                                                                               From Opportunity]));    
             setCon.setPageSize(Size);
       		 noOfrecords = setCon.getResultSize();            
            }
            return setCon;
        }
             
        set;
        
    }
    
    public PageReference refreshSize(){
        setCon.setPageSize(Size);
        return Null;
    }
    
    Public List<Opportunity> getOpportunities(){
        return (List<Opportunity>) setCon.getRecords();
    }
    
   
    
    public void selectOpp(){
        
        List<Opportunity> allOpp = [select Id,name,accountId,account.name,stageName,Amount,closeDate
                                                                               From Opportunity];
        
        set<Id> oppId = New Set<Id>();
        
        for(Opportunity opp : allOpp){
            
            oppId.add(opp.accountId);
        }
        
        List<Account> relatedAccount = [Select id,name from Account Where ID IN: oppId];
        
        wrapperList = new list<wrapperClass>();

        for(Opportunity childRec : allOpp ){
            
            for(Account parentRec : relatedAccount){
                
                if(parentRec.Id == childRec.AccountId){
                    wrapperClass wrap = New WrapperClass();
                    wrap.acc = parentRec;
                    wrap.opp = childRec;
                    wrapperList.add(wrap);
                }
                if(parentRec.Id == Null){
                    wrapperClass wrap = new WrapperClass();
                    wrap.opp = childRec;
                    wrapperList.add(wrap);
                }
            }
            
            
        }
        
    } 
    
    public void proceedWithSelected(){
        selectedWrapperlist = new List<wrapperClass>();
        normalList = false;
        selectedList = true;
        
        for(wrapperClass selectedWrapObj : wrapperList){
            if(selectedWrapObj.selected == True){
                selectedWrapperlist.add(selectedWrapObj);
                if(selectedWrapperlist != Null){
                apexPages.addMessage(New ApexPages.message(Apexpages.Severity.CONFIRM, 'Cheers !! Its Your Selected Opportunities' ));
                }
            }
        }
        
    }
    
    
    public Class wrapperClass{
        public Account acc{get;set;}
        public Opportunity opp{get;set;}
        public boolean selected{get;set;}
        public wrapperClass(){
            selected = false;
        }
    } 
}

****** Visualforce *********
 
<apex:page controller="OpportunityListWithWrapperClass" tabStyle="Opportunity">
    <apex:form >
        <apex:actionFunction name="refreshSizeOfPage" action="{!refreshSize}" reRender="pbId" status="fetchStatus" />
        <apex:sectionHeader title="Opportunity Details" subtitle="With Related Accounts"/>
        <apex:pageMessages />
        <apex:pageBlock id="pbId" title="Oportunity Details">
            <apex:commandButton value="Proceed With Selected" action="{!proceedWithSelected}"/>
            <apex:pageBlockSection columns="1">
                
                <apex:pageBlockTable value="{!wrapperList}" var="wrap" rendered="{!normalList}">
                    
                    <apex:column headerValue="Select">
                    	 <apex:inputCheckbox value="{!wrap.selected}"/>
                    </apex:column>
                    
                    <apex:column value="{!wrap.opp.name}"/>
                    
                    <apex:column value="{!wrap.acc.name}" />
                </apex:pageBlockTable>
                
                <apex:pageBlockTable value="{!selectedWrapperList}" var="wrap" rendered="{!selectedList}">
                    
                    <apex:column headerValue="Selected">
                        <apex:inputCheckbox value="{!wrap.selected}"/>
                    </apex:column> 
                    <apex:column value="{!wrap.opp.name}" />
                    <apex:column value="{!wrap.acc.name}" />
                    
                </apex:pageBlockTable>
                
                
             
            </apex:pageBlockSection>
            
            <apex:panelGrid columns="8">
                    <apex:selectList value="{!size}" multiselect="false" onchange="refreshSizeOfPage();" size="1">
                        <apex:selectOptions value="{!paginationSizeFixing}" />
                    </apex:selectList>
                   
                   <apex:commandButton status="fetchStatus" title="Previous Page" reRender="pbId" value="first"
                                       action="{!setCon.first}" disabled="{!!setCon.hasPrevious}"/>
					<apex:commandButton status="fetchStatus" title="Previous Page" value="Previous" reRender="pbId"
                                        action="{!setCon.Previous}" disabled="{!!setcon.hasPrevious}"/>
                    <apex:commandButton status="fetchStatus" title="Next Page" value="Next" reRender="pbId"
                                         action="{!setCon.Next}" disabled="{!!setCon.hasNext}"/>
                   <apex:commandButton status="fetchStatus" title="Last Page" value="Last" reRender="pbId"
                                       action="{!setCon.last}"  disabled="{!!setCon.hasNext}"/>
                   
                   <apex:outputLabel >
                   	{!(setCon.pageNumber * size)+1-size}-{!(setCon.pageNumber * Size)} of {!noOfRecords}
                   </apex:outputLabel>
                   
                   <apex:outputPanel >
                       <apex:actionStatus id="fetchStatus">
                           <apex:facet name="start">
                               <img src="https://media.giphy.com/media/l4eA8oZpx71oQ/giphy.gif" width="25" height="25"/>
                           </apex:facet>
                       </apex:actionStatus>
                   </apex:outputPanel>
                </apex:panelGrid>
            
            
        </apex:pageBlock>
    </apex:form>
</apex:page>


   <!--<apex:pageBlockTable value="{!wrapperList}" var="wrap" rendered="{!normalList}">
                    <apex:column headerValue="Select">
                    	 <apex:inputCheckbox value="{!wrap.selected}"/>
                    </apex:column>
                    <apex:column value="{!wrap.opp.name}" />      
                    <apex:column value="{!wrap.acc.name}" />
                </apex:pageBlockTable>
                </apex:pageBlockSection> 
            <apex:pageBlockSection columns="1"> 
                <apex:pageBlockTable value="{!selectedWrapperList}" var="wrap" rendered="{!selectedList}">
                    
                    <apex:column headerValue="Selected">
                        <apex:inputCheckbox value="{!wrap.selected}"/>
                    </apex:column> 
                    <apex:column value="{!wrap.opp.name}" />
                    <apex:column value="{!wrap.acc.name}" />
                    
                </apex:pageBlockTable> -->

**** Currently Showing Output****


User-added image



Thnaks in Advance!!

Regards,
Soundar 
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Soundar,


May I suggest you please refer the below link for reference.
https://developer.salesforce.com/forums/?id=906F0000000g28fIAA

Hope it will be helpful.

Please mark it as best answer if the information is informative.

Best Regards
Rahul Kumar