+ Start a Discussion
Sudhir_MeruSudhir_Meru 

Not able to stored previous page selected rows in wrapper class.

Hi, 

Below controller is a wrapper class using pagination.  Issue I am facing here is I am displaying pages in pagination User can select rows and insert the data. 

 Problem here is previous selected rows once moved to next page is not getting stored. 

 Only the currect page which is selected are getting stored not the previous page. Please suggest me how to fix. 

Controller
public with sharing class CCW_ContactPaginationController {

  //URL Passing Parameters.
  String PageContractId = ApexPages.currentPage().getParameters().get('ContractId');    
  String PageAccountId  = ApexPages.currentPage().getParameters().get('AccountId');  

  public Asset GetAccount{get;set;}
  public Asset GetContract{get;set;}
  public Asset GetExpireDate{get;set;}
  public Asset GetReseller{get;set;}
  public Asset GetDistributor{get;set;}
  public Boolean IncumbentReseller{get;set;}
  public Boolean Education{get;set;}
  public Asset GetOpportunity{get;set;}
  public Asset GetNewOpportunity{get;set;}
  public String ExpireTerms{get;set;}

  //Our collection to class/wrapper objects wrapAsset
  public List<CCWRowItem> wrapAssetList {get; set;}
  public List<Asset> selectedAssets{get;set;}
   /*
    *   item in context from the page
    */
    public String contextItem{get;set;}


    /*
    *   set controller
    */
    private ApexPages.StandardSetController setCon;
   
   
    /*
    *   the contact ids selected by the user
    */
    private Set<Id> selectedContactIds;
   
   
    /*
    *   constructor
    */
    public CCW_ContactPaginationController ()
    {
      GetAccount = new Asset();    //Get Account Id from Page
      GetContract = new Asset();   //Get Contract Name from Page  
      GetExpireDate = new Asset();   // Date Picker  
      GetReseller = new Asset();
      GetDistributor = new Asset(); 
      GetOpportunity = new Asset();   // Get Opportunity Id
      GetNewOpportunity = new Asset();  // Get New Opportunity Name      
      fetch_data();       
     }
   
  // public List<Asset> Asset_yourObjList{get;set;}
    
   public void fetch_data ()
   {
      
        //init variable
        this.selectedContactIds= new Set<Id>();
        //gather data set
       
         If ( GetAccount.AccountId == NULL || GetContract.Name == NULL )
         {  
           If ( PageContractId <> NULL )
           {
           Contract C;
           C = [SELECT Name FROM Contract WHERE Id = :PageContractId Limit 1];
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE last_contract_number__c = :C.Name  Limit 1000] );
                     }
           else If ( PageAccountId <> NULL )
           {
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE AccountId = :PageAccountId  Limit 1000] );
                     }  
         }
        
          If ( GetAccount.AccountId <> NULL && GetContract.Name == NULL )
          { 
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE AccountId = :GetAccount.AccountId Limit 1000] );
                    }
          Else If ( GetContract.Name <> NULL && GetAccount.AccountId == NULL )
          {
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE last_contract_number__c  = :GetContract.Name Limit 1000] );
                    } 
         Else If ( GetAccount.AccountId <> NULL && GetContract.Name <> NULL )
          {
         this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE AccountId = :GetAccount.AccountId and last_contract_number__c = :GetContract.Name  Limit 1000] );
                   }                                    
        this.setCon.setpageNumber(1);
        this.setCon.setPageSize(10);     
                  
   }
  
      
    /*
    *   handle item selected
    */
    public void doSelectItem(){       
        this.selectedContactIds.add(this.contextItem);       
    }
   
   
    /*
    *   handle item deselected
    */
    public void doDeselectItem(){       
        this.selectedContactIds.remove(this.contextItem);       
    }
   
   
    /*
    *   return count of selected items
    */
    public Integer getSelectedCount(){
       
        return this.selectedContactIds.size();
       
    }
   
   
    /*
    *   advance to next page
    */
    public void doNext(){
       
        if(this.setCon.getHasNext())
            this.setCon.next();

    }
   
   
    /*
    *   advance to previous page
    */
    public void doPrevious(){
       
        if(this.setCon.getHasPrevious())
            this.setCon.previous();
               
    }
   
    //public List<CCWRowItem> rows = new List<CCWRowItem>();
   
    public List<CCWRowItem> rows {get; set;}
    /*
    *   return current page of groups
    */
    public List<CCWRowItem> getContacts(){       
       
        rows = new List<CCWRowItem>();
       
        for(sObject r : this.setCon.getRecords()){
            Asset c = (Asset)r;
           
            CCWRowItem row = new CCWRowItem(c);
            if(this.selectedContactIds.contains(c.Id)){
                row.IsSelected=true;
            }
            else{
                row.IsSelected=false;
            }
            rows.add(row);           
        }
               
        return rows;
       
    }
 
// Store Selected Records to Object/Table
public void processSelected() {
    selectedAssets = new List<Asset>();
    list<Temp_Assets__c> TempAssetList = new list<Temp_Assets__c>();   
       
        for(CCWRowItem wrapAssetObj : rows  ) {
          if(wrapAssetObj.IsSelected == true) {
             selectedAssets.add(wrapAssetObj.tContact);
           } 
     }
       
       
       Account ResellerAct;
       Account DistributorAct; 
       Opportunity Oppt;        
                        
       for(Asset Act : selectedAssets)
            {              
              Temp_Assets__c TempAsset = new Temp_Assets__c();
              TempAsset.Name = 'Sudhir';
              TempAsset.AccountId__c = Act.AccountId;
              TempAsset.Product__c = Act.Product2Id;
              TempAsset.Serial_Number__c = Act.SerialNumber;
              TempAsset.Last_Contract_Number__c = Act.last_contract_number__c;
              TempAsset.Service_Start_Date__c = Act.Service_Start_Date_Min__c;
              TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
              //TempAsset.Service_End_Date__c = maxDate;
              TempAsset.Install_Date__c = Act.InstallDate; 
               If (GetReseller.AccountId <> NULL)
               {     
                ResellerAct = [ SELECT Id FROM Account WHERE ID = :GetReseller.AccountId Limit 1];
                TempAsset.Reseller__c = ResellerAct.Id;
                }
               If (GetDistributor.AccountId <> NULL )
                {
                DistributorAct = [ SELECT Id FROM Account WHERE ID = :GetDistributor.AccountId Limit 1];
                TempAsset.Distributor__c = DistributorAct.Id;
                }
               If ( GetOpportunity.Opportunity__c <> NULL )
                {
                Oppt = [SELECT Id FROM Opportunity WHERE ID = :GetOpportunity.Opportunity__c Limit 1];
                TempAsset.Existing_Opportunity__c = Oppt.Id;
                }               
              TempAsset.Incumbent_Reseller__c = IncumbentReseller;
              TempAsset.Education__c = Education;
              TempAsset.Expiry_Date__c = GetExpireDate.Expire_Date__c;
             
              TempAsset.New_Opportunity__c = GetNewOpportunity.New_Opportunity__c;
              TempAsset.Expiry_Term__c = ExpireTerms;
              //Add the selected Assets to the List
              TempAssetList.add(TempAsset);
            }
           
        Insert TempAssetList; 
       
    } 
   
    /*
    *   return whether previous page exists
    */
    public Boolean getHasPrevious(){
       
        return this.setCon.getHasPrevious();
       
    }
   
   
    /*
    *   return whether next page exists
    */
    public Boolean getHasNext(){
       
        return this.setCon.getHasNext();
   
    }
   
   
    /*
    *   return page number
    */
    public Integer getPageNumber(){
       
        return this.setCon.getPageNumber();
       
    }
   
   
    /*
    *    return total pages
    */
    Public Integer getTotalPages(){
   
        Decimal totalSize = this.setCon.getResultSize();
        Decimal pageSize = this.setCon.getPageSize();
       
        Decimal pages = totalSize/pageSize;
       
        return (Integer)pages.round(System.RoundingMode.CEILING);
    }
   
   
   
    /*
    *   helper class that represents a row
    */
    public with sharing class CCWRowItem{
       
        public Asset tContact{get;set;}
        public Boolean IsSelected{get;set;}
       
        public CCWRowItem(Asset c){
            this.tContact=c;
            this.IsSelected=false;
        }
       
    }
   
    
   
}


Visual Force


<apex:page controller="CCW_ContactPaginationController" showHeader="false" sidebar="false" readOnly="false" cache="false">
 
    <script type="text/javascript">

        /*
        *    function to handle checkbox selection
        */
        function doCheckboxChange(cb,itemId){

            if(cb.checked==true){
                aSelectItem(itemId);
            }
            else{
                aDeselectItem(itemId);
            }

        }

    </script>
   
<apex:sectionHeader subtitle="Create Renewal Quote" title="Meru Networks"/>

<apex:form >
              
       
     <apex:pageBlock >
       <apex:pageBlockButtons >
       <apex:commandButton value="Save Records" action="{!processSelected}"/>
       </apex:pageBlockButtons>
           
       <apex:pageBlockSection title="Install Base Report" id="mpb" collapsible="true" columns="1">
       
       
        <!-- handle selected item -->
        <apex:actionFunction name="aSelectItem" action="{!doSelectItem}" rerender="mpb">
            <apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
        </apex:actionFunction>
       
        <!-- handle deselected item -->
        <apex:actionFunction name="aDeselectItem" action="{!doDeselectItem}" rerender="mpb">
            <apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
        </apex:actionFunction>
           
            <!-- table of data -->
            <apex:pageBlockTable title="Assets" value="{!Contacts}" var="c">
                <apex:column >
                    <apex:facet name="header">Action</apex:facet>
                    <apex:inputCheckbox value="{!c.IsSelected}" onchange="doCheckboxChange(this,'{!c.tContact.Id}')"/>
                </apex:column>
                <apex:column value="{!c.tContact.AccountId}"/>
                <apex:column value="{!c.tContact.Product2Id}"/>
                <apex:column value="{!c.tContact.SerialNumber}"/>
                <apex:column value="{!c.tContact.last_contract_number__c}"/>
                <apex:column value="{!c.tContact.Service_Start_Date_Min__c}"/>
               <apex:column value="{!c.tContact.Service_End_Date_Max__c}"/>
               <apex:column value="{!c.tContact.InstallDate}"/>
            </apex:pageBlockTable>
       
           
           
            <apex:pageBlockSection collapsible="false" columns="4">
            <!-- count of selected items -->
            <apex:outputLabel value="[{!selectedCount} records selected]" />           
            <apex:outputLabel value=" (page {!pageNumber} of {!totalPages}) " />          
            <!-- next, previous and page info -->
            <apex:commandLink action="{!doPrevious}" rendered="{!hasPrevious}" value="Previous" />
            <apex:outputLabel rendered="{!NOT(hasPrevious)}" value="Previous" />                                  
            <apex:commandLink action="{!doNext}" rendered="{!hasNext}" value="Next" />
            <apex:outputLabel rendered="{!NOT(hasNext)}" value="Next" />
            </apex:pageBlockSection>
            </apex:pageBlockSection>

        </apex:pageBlock>    
        


</apex:form> 

</apex:page>

Thanks

Sudhir

Best Answer chosen by Sudhir_Meru
Swati GSwati G
Do following changes on the code.

Integer currentPageNumber = setCon.getPageNumber();

setCon.setpageNumber(1);

while(true){
    List<Asset>  TempAssetLists = (List<Asset>)setCon.getRecords();
    for(Asset assetIns : TempAssetLists  ) {
          if(this.selectedContactIds.contains(assetIns.Id)){
             selectedAssets.add(assetIns);
           }
     }
if(setCon.gethasNext()){
  setCon.next();
  }
  else{
  break;
  } 
 
}

setCon.setpageNumber(currentPageNumber);

All Answers

Swati GSwati G
Hi Sudhir,

Check if selectedContactIds contains the id of selected contacts when you select and click previous button.


Sudhir_MeruSudhir_Meru

Hi Swati, 

    It containts Id. Please suggest me how to modify this code so that all the selected page records must be saved

Thanks

Sudhir

Swati GSwati G
Your approach is correct. You are storing selected ids on set and using that to set selected item in wrapper list. Add some more logs to check if selectedContactIds contains id or not. Add log on getContacts method. System.debug('selectedContactIds: '+selectedContactIds); to check if it contains ids when you do next and previous button click.
Sudhir_MeruSudhir_Meru
Hi Swati, 

    As you suggesed I added system.debug I am able to see all 4 selected records below.

  USER_DEBUG|[164]|DEBUG|selectedContactIds: {02i11000000GkbAAAS, 02i11000000GkwcAAC, 02i11000000GlW8AAK, 02i11000000GpLOAA0

Thanks
Sudhir
Ramu_SFDCRamu_SFDC
Did not get the chance to review your complete code but being there done this multiple times. You should be able to accomplish this by using a temporary set collection variable that holds the selected id's and everytime the new set of records are requested by the pagination buttons, it method from where the wrapper data is being sent would be checking if the id's exist in the set collection and check the selection status accordingly.

Long story short, follow the approach as mentioned in the below article

http://blog.cloudclickware.com/2013/04/04/list-pagination-and-record-selection-with-visualforce/
Swati GSwati G
Ok, means set persists its data. can you also check what c.id is? add debug in for loop.

for(sObject r : this.setCon.getRecords()){
            Asset c = (Asset)r;
system.debug('c.Id: '+c.id);

Sudhir_MeruSudhir_Meru

Hi Swati, 

  It is printing all the 14 ID's in system.debug log these are the records id that are displayed.
 

Thanks

Sudhir

Swati GSwati G
Does any one matches with the ids in set?
Sudhir_MeruSudhir_Meru

Hi Ramu, 

   Can you give me a example how to add tempoary set collection in code and let me know. 

Thanks

Sudhir

Sudhir_MeruSudhir_Meru

Hi Swati,

  Only two records matched. 

c.id
02i11000000GillAAC
02i11000000GjCmAAK
02i11000000GgyNAAS
02i11000000GkbAAAS
02i11000000GjdbAAC
02i11000000GkpYAAS
02i11000000GlW8AAK
02i11000000Gkh5AAC
02i11000000GmP4AAK
02i11000000GhykAAC

selectedContactIds
{02i11000000GgyNAAS, 02i11000000GkwcAAC, 02i11000000GlW8AAK, 02i11000000GpLOAA0}


Thanks

Sudhir

Sudhir_MeruSudhir_Meru
Hi Swati, 

   Issue is I think as pagination is happening only that selected records are displayed and matched and it is not happening with the previous selected records. 

   Please suggest me how to fix this issue.

Thanks
Sudhir
Swati GSwati G
If they are matching then it should work. Your code should set isSelected as true for two records of that page.

if(this.selectedContactIds.contains(c.Id)){
          row.IsSelected=true;
  }
  else{
            row.IsSelected=false;
   }
Sudhir_MeruSudhir_Meru

Hi Swati,

  How set make isSelected as true for previous selected page. Please give me a example

Thanks

Sudhir

Ramu_SFDCRamu_SFDC
Hi Sudhir, Here you go. Remove the javascript in your VF page and use the native action function for this purpose as the below.

<apex:actionfunction name="runonce" action="{!doselectitem}" rerender="mpb,summarysection" status="status">                 
                    <apex:param name="firstparam" assignTo="{!Selected_Recordid}" value=""/>
                    <apex:param name="secondparam" assignTo="{!Checkbox_status}" value=""/>                  
</apex:actionfunction>

<apex:column >
                    <apex:facet name="header">Action</apex:facet>
                   <apex:inputCheckbox value="{!c.IsSelected}" onchange="runonce('{!c.tContact.Id}',this.checked)"/>
                </apex:column>


Controller :

Public String Selected_Recordid{get;set;}
Public boolean Checkbox_status{get;set;}

public void doSelectItem(){    
    if(Checkbox_status==true){      
        this.selectedIds.add(this.Selected_Recordid);
        Stats();
        }
        else{
        this.selectedIds.remove(this.Selected_Recordid);
        Stats();
        }

    }

** selectedIds is the set collection variable in my code

Hope this helps !!
Swati GSwati G
When you click previous it will call doPrevious method of controller and when action completes the page loads it will call getContacts which will return new list of records of the previous page which is current page now. As the selected ids are maintained on set while iterating it will check if id is present on set it yes then set isSelected=true.


Swati GSwati G
Are you facing problem in processSelected method as rows only contains current page items? So, method process on only current page.
Sudhir_MeruSudhir_Meru

Hi Swati, 

  Problem I am facing is it will insert only the currect page selected rows if I have selected previous page selected rows these are not getting stored.

Thanks

Sudhir

Swati GSwati G
You can set page to first page and start processing each page. See below code how you can create selectedAssets list.

setCon.setpageNumber(1);

while(true){
    List<CCWRowItem>  tempRows = setCon.getRecords();
    for(CCWRowItem wrapAssetObj : tempRows  ) {
          if(this.selectedContactIds.contains(wrapAssetObj.tContact.Id)){
             selectedAssets.add(wrapAssetObj.tContact);
           }
     }
  if(setCon.hasNext()){
  setCon.next();
  }
  else{
  break;
  }
   
}
Sudhir_MeruSudhir_Meru
Hi Ramu, 

  Thanks for your code. I modifed Visualforce as you mentioned I didnt get no errors.

  I am getting error in controller 

Error: Compile Error: Variable does not exist: selectedids at line 103 column 9

Controller

public with sharing class CCW_ContactPaginationController {

  //URL Passing Parameters.
  String PageContractId = ApexPages.currentPage().getParameters().get('ContractId');    
  String PageAccountId  = ApexPages.currentPage().getParameters().get('AccountId');  

  public Asset GetAccount{get;set;}
  public Asset GetContract{get;set;}
  public Asset GetExpireDate{get;set;}
  public Asset GetReseller{get;set;}
  public Asset GetDistributor{get;set;}
  public Boolean IncumbentReseller{get;set;}
  public Boolean Education{get;set;}
  public Asset GetOpportunity{get;set;}
  public Asset GetNewOpportunity{get;set;}
  public String ExpireTerms{get;set;}

  //Our collection to class/wrapper objects wrapAsset
  public List<CCWRowItem> wrapAssetList {get; set;}
  public List<Asset> selectedAssets{get;set;}
   /*
    *   item in context from the page
    */
    public String contextItem{get;set;}


    /*
    *   set controller
    */
    private ApexPages.StandardSetController setCon;
   
   
    /*
    *   the contact ids selected by the user
    */
    private Set<Id> selectedContactIds;
   
   
    /*
    *   constructor
    */
    public CCW_ContactPaginationController ()
    {
      GetAccount = new Asset();    //Get Account Id from Page
      GetContract = new Asset();   //Get Contract Name from Page  
      GetExpireDate = new Asset();   // Date Picker  
      GetReseller = new Asset();
      GetDistributor = new Asset(); 
      GetOpportunity = new Asset();   // Get Opportunity Id
      GetNewOpportunity = new Asset();  // Get New Opportunity Name      
      fetch_data();       
     }
   
  // public List<Asset> Asset_yourObjList{get;set;}
    
   public void fetch_data ()
   {
      
        //init variable
        this.selectedContactIds= new Set<Id>();
        //gather data set
       
         If ( GetAccount.AccountId == NULL || GetContract.Name == NULL )
         {  
           If ( PageContractId <> NULL )
           {
           Contract C;
           C = [SELECT Name FROM Contract WHERE Id = :PageContractId Limit 1];
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE last_contract_number__c = :C.Name  Limit 1000] );
                     }
           else If ( PageAccountId <> NULL )
           {
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE AccountId = :PageAccountId  Limit 1000] );
                     }  
         }
        
          If ( GetAccount.AccountId <> NULL && GetContract.Name == NULL )
          { 
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE AccountId = :GetAccount.AccountId Limit 1000] );
                    }
          Else If ( GetContract.Name <> NULL && GetAccount.AccountId == NULL )
          {
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE last_contract_number__c  = :GetContract.Name Limit 1000] );
                    } 
         Else If ( GetAccount.AccountId <> NULL && GetContract.Name <> NULL )
          {
         this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE AccountId = :GetAccount.AccountId and last_contract_number__c = :GetContract.Name  Limit 1000] );
                   }                                    
        this.setCon.setpageNumber(1);
        this.setCon.setPageSize(10);     
                  
   }
  
   
    Public String Selected_Recordid{get;set;}
    Public boolean Checkbox_status{get;set;}  
    /*
    *   handle item selected
    */
    public void doSelectItem(){       
        this.selectedContactIds.add(this.contextItem);
               
        if(Checkbox_status==true){     
        this.selectedIds.add(this.Selected_Recordid);
        Stats();
        }
        else{
        this.selectedIds.remove(this.Selected_Recordid);
        Stats();
        }
    }
   
   
    /*
    *   handle item deselected
    */
    public void doDeselectItem(){       
        this.selectedContactIds.remove(this.contextItem);       
    }
   
   
    /*
    *   return count of selected items
    */
    public Integer getSelectedCount(){
       
        return this.selectedContactIds.size();
       
    }
   
   
    /*
    *   advance to next page
    */
    public void doNext(){
       
        if(this.setCon.getHasNext())
            this.setCon.next();

    }
   
   
    /*
    *   advance to previous page
    */
    public void doPrevious(){
       
        if(this.setCon.getHasPrevious())
            this.setCon.previous();
               
    }
   
    //public List<CCWRowItem> rows = new List<CCWRowItem>();
   
    public List<CCWRowItem> rows {get; set;}
    /*
    *   return current page of groups
    */
    public List<CCWRowItem> getContacts(){       
       
        rows = new List<CCWRowItem>();
       
        for(sObject r : this.setCon.getRecords()){
            Asset c = (Asset)r;
             system.debug('c.Id: '+c.id);
            CCWRowItem row = new CCWRowItem(c);
            if(this.selectedContactIds.contains(c.Id)){
                row.IsSelected=true;
            }
            else{
                row.IsSelected=false;
            }
            rows.add(row);           
        }
         System.debug('selectedContactIds: '+selectedContactIds);       
       
        return rows;
       
    }
 
// Store Selected Records to Object/Table
public void processSelected() {
    selectedAssets = new List<Asset>();
    list<Temp_Assets__c> TempAssetList = new list<Temp_Assets__c>();   
       
        for(CCWRowItem wrapAssetObj : rows  ) {
          if(wrapAssetObj.IsSelected == true) {
             selectedAssets.add(wrapAssetObj.tContact);
           } 
        }
       
        /**********Added by Unnat*********************************/
        //below code should only execute if Expiry term has a value
        Date maxDate=Date.valueOf('2000-1-1');
        //Calculate the maximum Date off of the selected dates
        //if (Expiry_term !=null {
       
            //finds the latest expiry date out of the selected assets
            for (Asset assets: selectedAssets) {
                if(assets.Service_End_Date_Max__c > maxDate) {
                    maxDate=assets.Service_End_Date_Max__c;
                }
            }
            //There will be another condition to add the expiry term to the latest expiry date
            /*if (expiry_term== '1 Year') {
                maxDate=maxDate.addYears(1).addDays(1);
            }
            else if (expiry_term == '3 Year') {
                maxDate=maxDate.addYears(3).addDays(1);
            }
            else if (expirty_term == '5 Year') {
                maxDate=maxDate.addYears(5).addDays(1);
            }
        }
        else {
            maxDate= expiry_date;  
        } */
        /****************Completed by Unnat*****************************/
       Account ResellerAct;
       Account DistributorAct; 
       Opportunity Oppt;
             
       

      
      

        
       for(Asset Act : selectedAssets)
            {              
              Temp_Assets__c TempAsset = new Temp_Assets__c();
              TempAsset.Name = 'Sudhir';
              TempAsset.AccountId__c = Act.AccountId;
              TempAsset.Product__c = Act.Product2Id;
              TempAsset.Serial_Number__c = Act.SerialNumber;
              TempAsset.Last_Contract_Number__c = Act.last_contract_number__c;
              TempAsset.Service_Start_Date__c = Act.Service_Start_Date_Min__c;
              TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
              //TempAsset.Service_End_Date__c = maxDate;
              TempAsset.Install_Date__c = Act.InstallDate; 
               If (GetReseller.AccountId <> NULL)
               {     
                ResellerAct = [ SELECT Id FROM Account WHERE ID = :GetReseller.AccountId Limit 1];
                TempAsset.Reseller__c = ResellerAct.Id;
                }
               If (GetDistributor.AccountId <> NULL )
                {
                DistributorAct = [ SELECT Id FROM Account WHERE ID = :GetDistributor.AccountId Limit 1];
                TempAsset.Distributor__c = DistributorAct.Id;
                }
               If ( GetOpportunity.Opportunity__c <> NULL )
                {
                Oppt = [SELECT Id FROM Opportunity WHERE ID = :GetOpportunity.Opportunity__c Limit 1];
                TempAsset.Existing_Opportunity__c = Oppt.Id;
                }               
              TempAsset.Incumbent_Reseller__c = IncumbentReseller;
              TempAsset.Education__c = Education;
              TempAsset.Expiry_Date__c = GetExpireDate.Expire_Date__c;
             
              TempAsset.New_Opportunity__c = GetNewOpportunity.New_Opportunity__c;
              TempAsset.Expiry_Term__c = ExpireTerms;
              //Add the selected Assets to the List
              TempAssetList.add(TempAsset);
            }
           
        Insert TempAssetList; 
       
    } 
   
    /*
    *   return whether previous page exists
    */
    public Boolean getHasPrevious(){
       
        return this.setCon.getHasPrevious();
       
    }
   
   
    /*
    *   return whether next page exists
    */
    public Boolean getHasNext(){
       
        return this.setCon.getHasNext();
   
    }
   
   
    /*
    *   return page number
    */
    public Integer getPageNumber(){
       
        return this.setCon.getPageNumber();
       
    }
   
   
    /*
    *    return total pages
    */
    Public Integer getTotalPages(){
   
        Decimal totalSize = this.setCon.getResultSize();
        Decimal pageSize = this.setCon.getPageSize();
       
        Decimal pages = totalSize/pageSize;
       
        return (Integer)pages.round(System.RoundingMode.CEILING);
    }
   
   
   
    /*
    *   helper class that represents a row
    */
    public with sharing class CCWRowItem{
       
        public Asset tContact{get;set;}
        public Boolean IsSelected{get;set;}
       
        public CCWRowItem(Asset c){
            this.tContact=c;
            this.IsSelected=false;
        }
       
    }
 
      
    
   
}
Ramu_SFDCRamu_SFDC
Replace 'selectedids' with  'selectedContactIds' and you should be good.
Sudhir_MeruSudhir_Meru

Thanks Ramu, 

  Stats(); method does not exist in controller

Error: Compile Error: Method does not exist or incorrect signature: Stats() at line 104 column 9

Thanks

Sudhir

Ramu_SFDCRamu_SFDC
My bad, please remove the line that has stats();   where ever it appeared. That was another method in my code.
Sudhir_MeruSudhir_Meru

Hi Swati, 
 

  Where to add this code in controller

setCon.setpageNumber(1);

while(true){
    List<CCWRowItem>  tempRows = setCon.getRecords();
    for(CCWRowItem wrapAssetObj : tempRows  ) {
          if(this.selectedContactIds.contains(wrapAssetObj.tContact.Id)){
             selectedAssets.add(wrapAssetObj.tContact);
           }
     }
  if(setCon.hasNext()){
  setCon.next();
  }
  else{
  break;
  }
  


Please advice.

Thanks

Sudhir

Swati GSwati G
In processSelected method, remove first for look and insert this code.
Sudhir_MeruSudhir_Meru
Hi Swati, 

  I get this error  Error: Compile Error: Illegal assignment from LIST<SObject> to LIST<CCW_ContactPaginationController.CCWRowItem> at line 183 column 5

 Line 183 is List<CCWRowItem>  tempRows = setCon.getRecords();

// Store Selected Records to Object/Table
public void processSelected() {
    selectedAssets = new List<Asset>();
    list<Temp_Assets__c> TempAssetList = new list<Temp_Assets__c>();   
       
    /*    for(CCWRowItem wrapAssetObj : rows  ) {
          if(wrapAssetObj.IsSelected == true) {
             selectedAssets.add(wrapAssetObj.tContact);
           } 
        } */
       
    setCon.setpageNumber(1); 
   
    while(true){
    List<CCWRowItem>  tempRows = setCon.getRecords();
    for(CCWRowItem wrapAssetObj : tempRows  ) {
          if(this.selectedContactIds.contains(wrapAssetObj.tContact.Id)){
             selectedAssets.add(wrapAssetObj.tContact);
           }
     }
  if(setCon.hasNext()){
  setCon.next();
  }
  else{
  break;
  }
 
}
        
       Account ResellerAct;
       Account DistributorAct; 
       Opportunity Oppt;           
      

        
       for(Asset Act : selectedAssets)
            {              
              Temp_Assets__c TempAsset = new Temp_Assets__c();
              TempAsset.Name = 'Sudhir';
              TempAsset.AccountId__c = Act.AccountId;
              TempAsset.Product__c = Act.Product2Id;
              TempAsset.Serial_Number__c = Act.SerialNumber;
              TempAsset.Last_Contract_Number__c = Act.last_contract_number__c;
              TempAsset.Service_Start_Date__c = Act.Service_Start_Date_Min__c;
              TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
              //TempAsset.Service_End_Date__c = maxDate;
              TempAsset.Install_Date__c = Act.InstallDate; 
               If (GetReseller.AccountId <> NULL)
               {     
                ResellerAct = [ SELECT Id FROM Account WHERE ID = :GetReseller.AccountId Limit 1];
                TempAsset.Reseller__c = ResellerAct.Id;
                }
               If (GetDistributor.AccountId <> NULL )
                {
                DistributorAct = [ SELECT Id FROM Account WHERE ID = :GetDistributor.AccountId Limit 1];
                TempAsset.Distributor__c = DistributorAct.Id;
                }
               If ( GetOpportunity.Opportunity__c <> NULL )
                {
                Oppt = [SELECT Id FROM Opportunity WHERE ID = :GetOpportunity.Opportunity__c Limit 1];
                TempAsset.Existing_Opportunity__c = Oppt.Id;
                }               
              TempAsset.Incumbent_Reseller__c = IncumbentReseller;
              TempAsset.Education__c = Education;
              TempAsset.Expiry_Date__c = GetExpireDate.Expire_Date__c;
             
              TempAsset.New_Opportunity__c = GetNewOpportunity.New_Opportunity__c;
              TempAsset.Expiry_Term__c = ExpireTerms;
              //Add the selected Assets to the List
              TempAssetList.add(TempAsset);
            }
           
        Insert TempAssetList; 
       
    }
  
Sudhir_MeruSudhir_Meru

Hi Ramu, 

   Modified your code and added still I am able to save only two records previous page selected records am not able to save. 

Thanks

Sudhir

Swati GSwati G
You can typecase it 

List<CCWRowItem>  tempRows = (List<CCWRowItem>) setCon.getRecords();
Sudhir_MeruSudhir_Meru
Hi Swati,

  Modified   I get below error

Error: Compile Error: Incompatible types since an instance of LIST<SObject> is never an instance of LIST<CCW_ContactPaginationController.CCWRowItem> at line 183 column 35


Sudhir_MeruSudhir_Meru

Hi Ramu,

   Do I have to make any changes in your code please advice.
 

Thanks

Sudhir

Swati GSwati G
oops sorry. Its a list of asset. Here is new code.

setCon.setpageNumber(1);

while(true){
    List<Asset>  tempAssetList = (List<Asset>)setCon.getRecords();
    for(Asset assetIns : tempAssetList  ) {
          if(this.selectedContactIds.contains(assetIns.Id)){
             selectedAssets.add(assetIns);
           }
     }
  if(setCon.hasNext()){
  setCon.next();
  }
  else{
  break;
  }
   
}
Sudhir_MeruSudhir_Meru
Hi Swati, 

   I get this error now

Error: Compile Error: Method does not exist or incorrect signature: [ApexPages.StandardSetController].hasNext() at line 189 column 6


i.e if(setCon.hasNext()){
  setCon.next();
  }
  else{
  break;
  }

I comment this section But I am not able to insert records now I modifed your code as below I renamed the variable to TempAssetListwhich is highlighted below.  Please check

// Store Selected Records to Object/Table
public void processSelected() {
    selectedAssets = new List<Asset>();
    list<Temp_Assets__c> TempAssetList = new list<Temp_Assets__c>();   
       
    /*    for(CCWRowItem wrapAssetObj : rows  ) {
          if(wrapAssetObj.IsSelected == true) {
             selectedAssets.add(wrapAssetObj.tContact);
           } 
        } */
       
     setCon.setpageNumber(1);

while(true){
    List<Asset>  TempAssetLists = (List<Asset>)setCon.getRecords();
    for(Asset assetIns : TempAssetLists  ) {
          if(this.selectedContactIds.contains(assetIns.Id)){
             selectedAssets.add(assetIns);
           }
     }
/* if(setCon.hasNext()){
  setCon.next();
  }
  else{
  break;
  } */
  
}         
       Account ResellerAct;
       Account DistributorAct; 
       Opportunity Oppt;                    

        
       for(Asset Act : selectedAssets)
            {              
              Temp_Assets__c TempAsset = new Temp_Assets__c();
              TempAsset.Name = 'Sudhir';
              TempAsset.AccountId__c = Act.AccountId;
              TempAsset.Product__c = Act.Product2Id;
              TempAsset.Serial_Number__c = Act.SerialNumber;
              TempAsset.Last_Contract_Number__c = Act.last_contract_number__c;
              TempAsset.Service_Start_Date__c = Act.Service_Start_Date_Min__c;
              TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
              //TempAsset.Service_End_Date__c = maxDate;
              TempAsset.Install_Date__c = Act.InstallDate; 
               If (GetReseller.AccountId <> NULL)
               {     
                ResellerAct = [ SELECT Id FROM Account WHERE ID = :GetReseller.AccountId Limit 1];
                TempAsset.Reseller__c = ResellerAct.Id;
                }
               If (GetDistributor.AccountId <> NULL )
                {
                DistributorAct = [ SELECT Id FROM Account WHERE ID = :GetDistributor.AccountId Limit 1];
                TempAsset.Distributor__c = DistributorAct.Id;
                }
               If ( GetOpportunity.Opportunity__c <> NULL )
                {
                Oppt = [SELECT Id FROM Opportunity WHERE ID = :GetOpportunity.Opportunity__c Limit 1];
                TempAsset.Existing_Opportunity__c = Oppt.Id;
                }               
              TempAsset.Incumbent_Reseller__c = IncumbentReseller;
              TempAsset.Education__c = Education;
              TempAsset.Expiry_Date__c = GetExpireDate.Expire_Date__c;
             
              TempAsset.New_Opportunity__c = GetNewOpportunity.New_Opportunity__c;
              TempAsset.Expiry_Term__c = ExpireTerms;
              //Add the selected Assets to the List
              TempAssetList.add(TempAsset);
            }
           
        Insert TempAssetList; 
       
    }


 Thanks
Sudhir
Swati GSwati G
Use setCon.getHasNext() instead of hasNext()
Sudhir_MeruSudhir_Meru
Hi Swati, 

   Thanks Swati I am able to save 4 records after saving records page show only one record on screen It is going to last page Please make to main on same page. 

Thanks
Sudhir
Swati GSwati G
Do following changes on the code.

Integer currentPageNumber = setCon.getPageNumber();

setCon.setpageNumber(1);

while(true){
    List<Asset>  TempAssetLists = (List<Asset>)setCon.getRecords();
    for(Asset assetIns : TempAssetLists  ) {
          if(this.selectedContactIds.contains(assetIns.Id)){
             selectedAssets.add(assetIns);
           }
     }
if(setCon.gethasNext()){
  setCon.next();
  }
  else{
  break;
  } 
 
}

setCon.setpageNumber(currentPageNumber);
This was selected as the best answer
Sudhir_MeruSudhir_Meru

Hi Swati, 

  If possible after clicking on save can you suggest me how to close the page even this is fine. 
 

Thanks

Sudhir

Sudhir_MeruSudhir_Meru

Hi Swati, 

   You are GENIOUS in SFDC Thank You Very Much for you help It was  a great help for me to resolve this issue. 

    THANK YOU VERY MUCH YOU ARE GENIOUS 

Thanks

Sudhir

Swati GSwati G
I am glad to help you.
Sudhir_MeruSudhir_Meru
Hi Swati, 

  I need a help in same controller I want to add checkbox on each row and capture that inside custom object. Please suggest me how to capture checked checkbox value.

  Let me know if you need seprate question to be posted in forum 

Thanks
Sudhir
Swati GSwati G
Is that custom object related to asset? 
Sudhir_MeruSudhir_Meru
Hi Swati, 

   It is not releated to Asset I just need to add a column called Bundle Support which is a checkbox and if user check or uncheck I need to capture this boolean value inside custom object. 

  For exiting page I just need to add one more column which is a checkbox and capture this value

Thanks
Sudhir
   
Swati GSwati G
But that has to related to some object, so that we should be able to identity at which row that check box should be checked.
For example, when user checked some of the checkboxes and save it. And when user visits page again then the checkbox which was checked previously should be shown as checked. This is possible only if there is some relation between asset may be some common field or something.


Sudhir_MeruSudhir_Meru
Hi Swati, 

    Lets do like this I have created a custom field in asset object know as Bundle_Support__c this will be a checkbox dispalyed in visualforce page. 

  When user check or uncheck based on that value has to be insert inside custom object.

I tried as mentioned below but i get following error.   

System.VisualforceException: Modified rows exist in the records collection!

I just need checkbox on eachrow which every is checked it has to be stored simple :) Please suggest me how to do

Controller

public with sharing class CCW_ContactPaginationController {

  //URL Passing Parameters.
  String PageContractId = ApexPages.currentPage().getParameters().get('ContractId');    
  String PageAccountId  = ApexPages.currentPage().getParameters().get('AccountId');  

  public Asset GetAccount{get;set;}
  public Asset GetContract{get;set;}
  public Asset GetExpireDate{get;set;}
  public Asset GetReseller{get;set;}
  public Asset GetDistributor{get;set;}
  public Boolean IncumbentReseller{get;set;}
  public Boolean Education{get;set;}
  public Asset GetOpportunity{get;set;}
  public Asset GetNewOpportunity{get;set;}
  public String ExpireTerms{get;set;}
  public Boolean BundSuprt{get;set;}
  public Boolean Skilled {get;set;}
 
  //Our collection to class/wrapper objects wrapAsset
  public List<CCWRowItem> wrapAssetList {get; set;}
  public List<Asset> selectedAssets{get;set;}
   /*
    *   item in context from the page
    */
    public String contextItem{get;set;}


    /*
    *   set controller
    */
    private ApexPages.StandardSetController setCon;
   
   
    /*
    *   the contact ids selected by the user
    */
    private Set<Id> selectedContactIds;
   
   
    /*
    *   constructor
    */
    public CCW_ContactPaginationController ()
    {
      GetAccount = new Asset();    //Get Account Id from Page
      GetContract = new Asset();   //Get Contract Name from Page  
      GetExpireDate = new Asset();   // Date Picker  
      GetReseller = new Asset();
      GetDistributor = new Asset(); 
      GetOpportunity = new Asset();   // Get Opportunity Id
      GetNewOpportunity = new Asset();  // Get New Opportunity Name      
      fetch_data();       
     }
   
  // public List<Asset> Asset_yourObjList{get;set;}
    
   public void fetch_data ()
   {
      
        //init variable
        this.selectedContactIds= new Set<Id>();
        //gather data set
       
         If ( GetAccount.AccountId == NULL || GetContract.Name == NULL )
         {  
           If ( PageContractId <> NULL )
           {
           Contract C;
           C = [SELECT Name FROM Contract WHERE Id = :PageContractId Limit 1];
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_number__c = :C.Name Order by Service_End_Date_Max__c Desc  Limit 1000] );
                     }
           else If ( PageAccountId <> NULL )
           {
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :PageAccountId Order by Service_End_Date_Max__c Desc   Limit 1000] );
                     }  
         }
        
          If ( GetAccount.AccountId <> NULL && GetContract.Name == NULL )
          { 
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :GetAccount.AccountId Order by Service_End_Date_Max__c Desc  Limit 1000] );
                    }
          Else If ( GetContract.Name <> NULL && GetAccount.AccountId == NULL )
          {
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_number__c  = :GetContract.Name Order by Service_End_Date_Max__c Desc  Limit 1000] );
                    } 
         Else If ( GetAccount.AccountId <> NULL && GetContract.Name <> NULL )
          {
         this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :GetAccount.AccountId and last_contract_number__c = :GetContract.Name  Order by Service_End_Date_Max__c Desc  Limit 1000] );
                   }                                    
        this.setCon.setpageNumber(1);
        this.setCon.setPageSize(10);     
                  
   }
  
      
    /*
    *   handle item selected
    */
    public void doSelectItem(){       
        this.selectedContactIds.add(this.contextItem);       
    }
   
   
    /*
    *   handle item deselected
    */
    public void doDeselectItem(){       
        this.selectedContactIds.remove(this.contextItem);       
    }
   
   
    /*
    *   return count of selected items
    */
    public Integer getSelectedCount(){
       
        return this.selectedContactIds.size();
       
    }
   
   
    /*
    *   advance to next page
    */
    public void doNext(){
       
        if(this.setCon.getHasNext())
            this.setCon.next();

    }
   
   
    /*
    *   advance to previous page
    */
    public void doPrevious(){
       
        if(this.setCon.getHasPrevious())
            this.setCon.previous();
               
    }
   
    //public List<CCWRowItem> rows = new List<CCWRowItem>();
   
    public List<CCWRowItem> rows {get; set;}
    /*
    *   return current page of groups
    */
    public List<CCWRowItem> getContacts(){       
       
        rows = new List<CCWRowItem>();
       
        for(sObject r : this.setCon.getRecords()){
            Asset c = (Asset)r;
           
            CCWRowItem row = new CCWRowItem(c);
            if(this.selectedContactIds.contains(c.Id)){
                row.IsSelected=true;
            }
            else{
                row.IsSelected=false;
            }
            rows.add(row);           
        }
               
        return rows;
       
    }
 
// Store Selected Records to Object/Table
public void processSelected() {
    Integer currentPageNumber = setCon.getPageNumber();
    selectedAssets = new List<Asset>().deepClone(true, true, true);
    list<Temp_Assets__c> TempAssetList = new list<Temp_Assets__c>();   
       
    /*    for(CCWRowItem wrapAssetObj : rows  ) {
          if(wrapAssetObj.IsSelected == true) {
             selectedAssets.add(wrapAssetObj.tContact);
           } 
        } */
       
     setCon.setpageNumber(1);

while(true){
    List<Asset>  TempAssetLists = (List<Asset>)setCon.getRecords().deepClone(true, true, true);
    for(Asset assetIns : TempAssetLists  ) {
          if(this.selectedContactIds.contains(assetIns.Id)){
             selectedAssets.add(assetIns);
           }
     }
if(setCon.getHasNext()){
  setCon.next();
  }
  else{
  break;
  }
  

       Account ResellerAct;
       Account DistributorAct; 
       Opportunity Oppt;          
                           
       for(Asset Act : selectedAssets)
            {              
              Temp_Assets__c TempAsset = new Temp_Assets__c();
              TempAsset.Name = 'Sudhir';
              TempAsset.AccountId__c = Act.AccountId;
              TempAsset.Product__c = Act.Product2Id;
              TempAsset.Serial_Number__c = Act.SerialNumber;
              TempAsset.Last_Contract_Number__c = Act.last_contract_number__c;
              TempAsset.Service_Start_Date__c = Act.Service_Start_Date_Min__c;
              TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
              TempAsset.Install_Date__c = Act.InstallDate; 
               If (GetReseller.AccountId <> NULL)
               {     
                ResellerAct = [ SELECT Id FROM Account WHERE ID = :GetReseller.AccountId Limit 1];
                TempAsset.Reseller__c = ResellerAct.Id;
                }
               If (GetDistributor.AccountId <> NULL )
                {
                DistributorAct = [ SELECT Id FROM Account WHERE ID = :GetDistributor.AccountId Limit 1];
                TempAsset.Distributor__c = DistributorAct.Id;
                }
               If ( GetOpportunity.Opportunity__c <> NULL )
                {
                Oppt = [SELECT Id FROM Opportunity WHERE ID = :GetOpportunity.Opportunity__c Limit 1];
                TempAsset.Existing_Opportunity__c = Oppt.Id;
                }               
              TempAsset.Incumbent_Reseller__c = IncumbentReseller;
              TempAsset.Education__c = Education;
              TempAsset.Expiry_Date__c = GetExpireDate.Expire_Date__c;
             
              TempAsset.New_Opportunity__c = GetNewOpportunity.New_Opportunity__c;
              TempAsset.Expiry_Term__c = ExpireTerms;
              TempAsset.Bundle_Support__c = Act.Bundle_Support__c;
                             //Add the selected Assets to the List
              TempAssetList.add(TempAsset);
            }
           
        Insert TempAssetList; 
       
        setCon.setpageNumber(currentPageNumber);
       
    } 
   
    /*
    *   return whether previous page exists
    */
    public Boolean getHasPrevious(){
       
        return this.setCon.getHasPrevious();
       
    }
   
   
    /*
    *   return whether next page exists
    */
    public Boolean getHasNext(){
       
        return this.setCon.getHasNext();
   
    }
   
   
    /*
    *   return page number
    */
    public Integer getPageNumber(){
       
        return this.setCon.getPageNumber();
       
    }
   
   
    /*
    *    return total pages
    */
    Public Integer getTotalPages(){
   
        Decimal totalSize = this.setCon.getResultSize();
        Decimal pageSize = this.setCon.getPageSize();
       
        Decimal pages = totalSize/pageSize;
       
        return (Integer)pages.round(System.RoundingMode.CEILING);
    }
   
   
  
   
    /*
    *   helper class that represents a row
    */
    public with sharing class CCWRowItem{
       
        public Asset tContact{get;set;}
        public Boolean IsSelected{get;set;}
        public Boolean BundelSelected{get;set;}
        
        public CCWRowItem(Asset c){
            this.tContact=c;
            this.IsSelected=false;
            this.BundelSelected=false;
        }
       
    }
 
      
    
   
}


Visual Force
<!-- table of data -->
            <apex:pageBlockTable title="Assets" value="{!Contacts}" var="c" id="reportblocktable">
                <apex:column >
                    <apex:facet name="header">Action</apex:facet>
                    <apex:inputCheckbox value="{!c.IsSelected}" onclick="doCheckboxChange(this,'{!c.tContact.Id}')"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">Bundle Support</apex:facet>
                    <apex:inputCheckbox value="{!c.tContact.Bundle_Support__c}" />               
                 </apex:column>
                <apex:column value="{!c.tContact.AccountId}"/>
                <apex:column value="{!c.tContact.Product2Id}"/>
                <apex:column value="{!c.tContact.SerialNumber}"/>
                <apex:column value="{!c.tContact.last_contract_number__c}"/>
                <apex:column value="{!c.tContact.Service_Start_Date_Min__c}"/>
               <apex:column value="{!c.tContact.Service_End_Date_Max__c}"/>
               <apex:column value="{!c.tContact.InstallDate}"/>
                 <apex:inlineEditSupport event="ondblClick"
                        showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" />
            </apex:pageBlockTable>
Sudhir_MeruSudhir_Meru
Hi Swati, 

  Thanks for your help on pagination I need am getting below error in controller please suggest me how to fix this issue 

System.NullPointerException: Attempt to de-reference a null object

I get below error and line 97 and line 60 from controller. I am doing pagination using wrapper class 

Class.CCW_ContactPaginationController.fetch_data: line 97, column 1
Class.CCW_ContactPaginationController.<init>: line 60, column 1

public with sharing class CCW_ContactPaginationController {

  //URL Passing Parameters.
  String PageContractId = ApexPages.currentPage().getParameters().get('ContractId');   
  String PageAccountId  = ApexPages.currentPage().getParameters().get('AccountId'); 

  public Asset GetAccount{get;set;}
  public Asset GetContract{get;set;}
  public Asset GetExpireDate{get;set;}
  public Asset GetReseller{get;set;}
  public Asset GetDistributor{get;set;}
  public String IncumbentReseller{get;set;}
  public String Education{get;set;}
  public Asset GetOpportunity{get;set;}
  public Asset GetNewOpportunity{get;set;}
  public String ExpireTerms{get;set;}
  public boolean bundsprt{get;set;}

  //Our collection to class/wrapper objects wrapAsset
  public List<CCWRowItem> wrapAssetList {get; set;}
  public List<Asset> selectedAssets{get;set;}
   /*
    *   item in context from the page
    */
    public String contextItem{get;set;}
    public String contextItem2{get;set;}


    /*
    *   set controller
    */
    private ApexPages.StandardSetController setCon;
  
  
    /*
    *   the contact ids selected by the user
    */
    private Set<Id> selectedContactIds;
    private Set<Id> selectedContactIds2= new set<Id>();
  
  
    /*
    *   constructor
    */
    public CCW_ContactPaginationController ()
    {
      GetAccount = new Asset();    //Get Account Id from Page
      GetContract = new Asset();   //Get Contract Name from Page 
      GetExpireDate = new Asset();   // Date Picker 
      GetReseller = new Asset();
      GetDistributor = new Asset();
      GetOpportunity = new Asset();   // Get Opportunity Id
      GetNewOpportunity = new Asset();  // Get New Opportunity Name  
      oppreseller = new Opportunity(); 
      fetch_data();      
     }
  
     
   public void fetch_data ()
   {
     
        //init variable
        this.selectedContactIds= new Set<Id>();
        //gather data set
      
         If ( GetAccount.AccountId == NULL || GetContract.Name == NULL )
         { 
           If ( PageContractId <> NULL )
           {
           Contract C;
           C = [SELECT Name FROM Contract WHERE Id = :PageContractId Limit 1];
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_number__c = :C.Name Order by Service_End_Date_Max__c Desc  Limit 1000] );
                     }
           else If ( PageAccountId <> NULL )
           {
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :PageAccountId Order by Service_End_Date_Max__c Desc   Limit 1000] );
                     } 
         }
       
          If ( GetAccount.AccountId <> NULL && GetContract.Name == NULL )
          {
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :GetAccount.AccountId Order by Service_End_Date_Max__c Desc  Limit 1000] );
                    }
          Else If ( GetContract.Name <> NULL && GetAccount.AccountId == NULL )
          {
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_number__c  = :GetContract.Name Order by Service_End_Date_Max__c Desc  Limit 1000] );
                    }
         Else If ( GetAccount.AccountId <> NULL && GetContract.Name <> NULL )
          {
         this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :GetAccount.AccountId and last_contract_number__c = :GetContract.Name  Order by Service_End_Date_Max__c Desc  Limit 1000] );
                   }                                   
        this.setCon.setpageNumber(1);
        this.setCon.setPageSize(25);                      
   } 
     
    /*
    *   handle item selected
    */
    public void doSelectItem(){      
        this.selectedContactIds.add(this.contextItem);      
    }
  
    public void doSelectItem2(){      
        this.selectedContactIds2.add(this.contextItem2);      
    }
  
  
    /*
    *   handle item deselected
    */
    public void doDeselectItem(){      
        this.selectedContactIds.remove(this.contextItem);      
    }
  
    public void doDeselectItem2(){      
        this.selectedContactIds2.remove(this.contextItem2);      
    }
  
  
    /*
    *   return count of selected items
    */
    public Integer getSelectedCount(){
      
        return this.selectedContactIds.size();
      
    }
  
  
    /*
    *   advance to next page
    */
    public void doNext(){
      
        if(this.setCon.getHasNext())
            this.setCon.next();

    }
  
  
    /*
    *   advance to previous page
    */
    public void doPrevious(){
      
        if(this.setCon.getHasPrevious())
            this.setCon.previous();
              
    }
  
    //public List<CCWRowItem> rows = new List<CCWRowItem>();
  
    public List<CCWRowItem> rows {get; set;}
    /*
    *   return current page of groups
    */
    public List<CCWRowItem> getContacts(){      
      
        rows = new List<CCWRowItem>();
      
        for(sObject r : this.setCon.getRecords()){
            Asset c = (Asset)r;
          
            CCWRowItem row = new CCWRowItem(c);
            if(this.selectedContactIds.contains(c.Id)){
                row.IsSelected=true;
                if (this.selectedContactIds2.contains(c.Id)){
                    row.BundelSelected=true;
                    bundsprt=true;
                }
                else {
                    row.BundelSelected=false;
                    bundsprt=false;
                }

            }
            else {
                row.IsSelected=false;
            }
            rows.add(row);          
        }
              
        return rows;
      
    }

// Store Selected Records to Object/Table
public void processSelected() {
    Integer currentPageNumber = setCon.getPageNumber();
    selectedAssets = new List<Asset>();
    list<Temp_Assets__c> TempAssetList = new list<Temp_Assets__c>();
      
      
     setCon.setpageNumber(1);

while(true){
    List<Asset>  TempAssetLists = (List<Asset>)setCon.getRecords();
    for(Asset assetIns : TempAssetLists  ) {
          if(this.selectedContactIds.contains(assetIns.Id)){
             selectedAssets.add(assetIns);
           
           
           }
     }
if(setCon.getHasNext()){
  setCon.next();
  }
  else{
  break;
  }
 
}          
       Account ResellerAct;
       Account DistributorAct;
       Opportunity Oppt;         
                          
       for(Asset Act : selectedAssets)
            {             
              Temp_Assets__c TempAsset = new Temp_Assets__c();
              TempAsset.Name = 'Sudhir';
              TempAsset.AccountId__c = Act.AccountId;
              TempAsset.Product__c = Act.Product2Id;
              //Added by Unnat
              TempAsset.Product_lookup__c= Act.Product2Id;
              TempAsset.Serial_Number__c = Act.SerialNumber;
              TempAsset.Last_Contract_Number__c = Act.last_contract_number__c;
              TempAsset.Service_Start_Date__c = Act.Service_Start_Date_Min__c;
              //TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
              /***************Added by Unnat********************************************/
              if (Act.Service_End_Date_Max__c != null) {
                  TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
              }
              else {
                   TempAsset.Service_End_Date__c = Act.InstallDate;
              }

              TempAsset.Install_Date__c = Act.InstallDate;
               If (GetReseller.AccountId <> NULL)
               {    
                ResellerAct = [ SELECT Id FROM Account WHERE ID = :GetReseller.AccountId Limit 1];
                TempAsset.Reseller__c = ResellerAct.Id;             
                }
               If (GetDistributor.AccountId <> NULL )
                {
                DistributorAct = [ SELECT Id FROM Account WHERE ID = :GetDistributor.AccountId Limit 1];
                TempAsset.Distributor__c = DistributorAct.Id;
                }
               If ( GetOpportunity.Opportunity__c <> NULL )
                {
                Oppt = [SELECT Id FROM Opportunity WHERE ID = :GetOpportunity.Opportunity__c Limit 1];
                TempAsset.Existing_Opportunity__c = Oppt.Id;
                }              
              TempAsset.Incumbent_Reseller__c = IncumbentReseller;
              TempAsset.Education__c = Education;
              //TempAsset.Expiry_Date__c = GetExpireDate.Expire_Date__c;
              TempAsset.Expiry_Date__c= maxDate;
            
              TempAsset.New_Opportunity__c = GetNewOpportunity.New_Opportunity__c;
              TempAsset.Expiry_Term__c = ExpireTerms;
            
                /* Insert Bundel Checkbox Value */              
                if (this.selectedContactIds2.contains(Act.Id)){
                    bundsprt=true;
                }
                else {
                    bundsprt=false;
                }
  
              
                TempAsset.Bundle_Support__c = bundsprt;
              System.debug('== Bundle Value is: ' + bundsprt);
            
                             //Add the selected Assets to the List
              TempAssetList.add(TempAsset);
            }
          
        Insert TempAssetList;
      
        setCon.setpageNumber(currentPageNumber);
      
    }
  
    /*
    *   return whether previous page exists
    */
    public Boolean getHasPrevious(){
      
        return this.setCon.getHasPrevious();
      
    }
  
  
    /*
    *   return whether next page exists
    */
    public Boolean getHasNext(){
      
        return this.setCon.getHasNext();
  
    }
  
  
    /*
    *   return page number
    */
    public Integer getPageNumber(){
      
        return this.setCon.getPageNumber();
      
    }
  
  
    /*
    *    return total pages
    */
    Public Integer getTotalPages(){
  
        Decimal totalSize = this.setCon.getResultSize();
        Decimal pageSize = this.setCon.getPageSize();
      
        Decimal pages = totalSize/pageSize;
      
        return (Integer)pages.round(System.RoundingMode.CEILING);
    }
  
  
 
  
    /*
    *   helper class that represents a row
    */
    public with sharing class CCWRowItem{
      
        public Asset tContact{get;set;}
        public Boolean IsSelected{get;set;}
        public Boolean BundelSelected{get;set;}
       
        public CCWRowItem(Asset c){
            this.tContact=c;          
            this.IsSelected=false;
            this.BundelSelected=false;
        }
      
    }
      
}
Sudhir_MeruSudhir_Meru
Hi Swati,

 System.NullPointerException: Attempt to de-reference a null object 

Error is coming when I navigate more 5 page after than i get this error when i click pagination

Thanks
Sudhir
Swati GSwati G
Hi,

You can add check that this.setCon != null.
Sudhir_MeruSudhir_Meru

Hi Swati,

  I added like this I get Error: Compile Error: Expression cannot be a statement at line 97 column 9

        this.setCon != null;                                          
        this.setCon.setpageNumber(1);
        this.setCon.setPageSize(10);

Please suggest me where to add this condition

Thanks

Sudhir

Sudhir_MeruSudhir_Meru
Hi Swati

  add this condition now i am getting error in line 173 

if ( this.setCon != null )
         {                                         
        this.setCon.setpageNumber(1);
        this.setCon.setPageSize(10);     
        }


line 173 is

public List<CCWRowItem> getContacts(){       
       
        rows = new List<CCWRowItem>();
       
        for(sObject r : this.setCon.getRecords()){      // line 173
            Asset c = (Asset)r;
           
            CCWRowItem row = new CCWRowItem(c);
            if(this.selectedContactIds.contains(c.Id)){
                row.IsSelected=true;
                if (this.selectedContactIds2.contains(c.Id)){
                    row.BundelSelected=true;
                    bundsprt=true;
                }
                else {
                    row.BundelSelected=false;
                    bundsprt=false;
                }

            }
            else {
                row.IsSelected=false;
            }
            rows.add(row);           
        }
               
        return rows;
       
    }
Swati GSwati G
Replace 3 lines with the below 3 lines

if(this.setCon != null){                                        
        this.setCon.setpageNumber(1);
        this.setCon.setPageSize(10);
}
Sudhir_MeruSudhir_Meru
Hi Swati, 

  I added your condition where i got the error now in line 379 am getting now i am able to paginate more than 10 pages. Please suggest me how to fix this in controller


public with sharing class CCW_ContactPaginationController {

  //URL Passing Parameters.
  String PageContractId = ApexPages.currentPage().getParameters().get('ContractId');    
  String PageAccountId  = ApexPages.currentPage().getParameters().get('AccountId');  

  public Asset GetAccount{get;set;}
  public Asset GetContract{get;set;}
  public Asset GetExpireDate{get;set;}
  public Asset GetReseller{get;set;}
  public Asset GetDistributor{get;set;}
  public String IncumbentReseller{get;set;}
  public String Education{get;set;}
  public Asset GetOpportunity{get;set;}
  public Asset GetNewOpportunity{get;set;}
  public String ExpireTerms{get;set;}
  public boolean bundsprt{get;set;}
  public opportunity oppreseller {get;set;}

  /* public list<Account> GetReseller(){
    return [select id from account where Partner_Type__c = 'RESELLER'];       
    } */
 
  //Our collection to class/wrapper objects wrapAsset
  public List<CCWRowItem> wrapAssetList {get; set;}
  public List<Asset> selectedAssets{get;set;}
   /*
    *   item in context from the page
    */
    public String contextItem{get;set;}
    public String contextItem2{get;set;}


    /*
    *   set controller
    */
    private ApexPages.StandardSetController setCon;
   
   
    /*
    *   the contact ids selected by the user
    */
    private Set<Id> selectedContactIds;
    private Set<Id> selectedContactIds2= new set<Id>();
   
   
    /*
    *   constructor
    */
    public CCW_ContactPaginationController ()
    {
      GetAccount = new Asset();    //Get Account Id from Page
      GetContract = new Asset();   //Get Contract Name from Page  
      GetExpireDate = new Asset();   // Date Picker  
      GetReseller = new Asset();
      GetDistributor = new Asset(); 
      GetOpportunity = new Asset();   // Get Opportunity Id
      GetNewOpportunity = new Asset();  // Get New Opportunity Name   
      oppreseller = new Opportunity();  
      fetch_data();       
     }
   
      
   public void fetch_data ()
   {
      
        //init variable
        this.selectedContactIds= new Set<Id>();
        //gather data set
       
         If ( GetAccount.AccountId == NULL || GetContract.Name == NULL )
         {  
           If ( PageContractId <> NULL )
           {
           Contract C;
           C = [SELECT Name FROM Contract WHERE Id = :PageContractId Limit 1];
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_number__c = :C.Name Order by Service_End_Date_Max__c Desc  Limit 1000] );
                     }
           else If ( PageAccountId <> NULL )
           {
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :PageAccountId Order by Service_End_Date_Max__c Desc   Limit 1000] );
                     }  
         }
        
          If ( GetAccount.AccountId <> NULL && GetContract.Name == NULL )
          { 
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :GetAccount.AccountId Order by Service_End_Date_Max__c Desc  Limit 1000] );
                    }
          Else If ( GetContract.Name <> NULL && GetAccount.AccountId == NULL )
          {
           this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_number__c  = :GetContract.Name Order by Service_End_Date_Max__c Desc  Limit 1000] );
                    } 
         Else If ( GetAccount.AccountId <> NULL && GetContract.Name <> NULL )
          {
         this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :GetAccount.AccountId and last_contract_number__c = :GetContract.Name  Order by Service_End_Date_Max__c Desc  Limit 1000] );
                   }  
                  
                  
        if(this.setCon != null){                                       
        this.setCon.setpageNumber(1);
        this.setCon.setPageSize(10);
        }
                  
   }
  
      
    /*
    *   handle item selected
    */
    public void doSelectItem(){       
        this.selectedContactIds.add(this.contextItem);       
    }
   
    public void doSelectItem2(){       
        this.selectedContactIds2.add(this.contextItem2);       
    }
   
   
    /*
    *   handle item deselected
    */
    public void doDeselectItem(){       
        this.selectedContactIds.remove(this.contextItem);       
    }
   
    public void doDeselectItem2(){       
        this.selectedContactIds2.remove(this.contextItem2);       
    }
   
   
    /*
    *   return count of selected items
    */
    public Integer getSelectedCount(){
       
        return this.selectedContactIds.size();
       
    }
   
   
    /*
    *   advance to next page
    */
    public void doNext(){
        if(this.setCon != null){ 
        if(this.setCon.getHasNext())
            this.setCon.next();
          }
    }
   
   
    /*
    *   advance to previous page
    */
    public void doPrevious(){
        if(this.setCon != null){ 
        if(this.setCon.getHasPrevious())
            this.setCon.previous();
           }    
    }
   
    //public List<CCWRowItem> rows = new List<CCWRowItem>();
   
    public List<CCWRowItem> rows {get; set;}
    /*
    *   return current page of groups
    */
    public List<CCWRowItem> getContacts(){       
       
        rows = new List<CCWRowItem>();
       
        if(this.setCon != null){
        for(sObject r : this.setCon.getRecords()){
            Asset c = (Asset)r;
           
            CCWRowItem row = new CCWRowItem(c);
            if(this.selectedContactIds.contains(c.Id)){
                row.IsSelected=true;
                if (this.selectedContactIds2.contains(c.Id)){
                    row.BundelSelected=true;
                    bundsprt=true;
                }
                else {
                    row.BundelSelected=false;
                    bundsprt=false;
                }

            }
            else {
                row.IsSelected=false;
            }
            rows.add(row);           
        }
      }         
        return rows;
       
    }
 
// Store Selected Records to Object/Table
public void processSelected() {
    Integer currentPageNumber = setCon.getPageNumber();
    selectedAssets = new List<Asset>();
    list<Temp_Assets__c> TempAssetList = new list<Temp_Assets__c>(); 
       
       
     setCon.setpageNumber(1);

while(true){
    List<Asset>  TempAssetLists = (List<Asset>)setCon.getRecords();
    for(Asset assetIns : TempAssetLists  ) {
          if(this.selectedContactIds.contains(assetIns.Id)){
             selectedAssets.add(assetIns);
            
            
           }
     }
if(setCon.getHasNext()){
  setCon.next();
  }
  else{
  break;
  }
  
}     
       
       Account ResellerAct;
       Account DistributorAct; 
       Opportunity Oppt;          
                           
       for(Asset Act : selectedAssets)
            {              
              Temp_Assets__c TempAsset = new Temp_Assets__c();
              TempAsset.Name = 'Sudhir';
              TempAsset.AccountId__c = Act.AccountId;
              TempAsset.Product__c = Act.Product2Id;
              //Added by Unnat
              TempAsset.Product_lookup__c= Act.Product2Id;
              TempAsset.Serial_Number__c = Act.SerialNumber;
              TempAsset.Last_Contract_Number__c = Act.last_contract_number__c;
              TempAsset.Service_Start_Date__c = Act.Service_Start_Date_Min__c;
              //TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
              /***************Added by Unnat********************************************/
              if (Act.Service_End_Date_Max__c != null) {
                  TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
              }
              else {
                   TempAsset.Service_End_Date__c = Act.InstallDate;
              }

              TempAsset.Install_Date__c = Act.InstallDate; 
               If (GetReseller.AccountId <> NULL)
               {     
                ResellerAct = [ SELECT Id FROM Account WHERE ID = :GetReseller.AccountId Limit 1];
                TempAsset.Reseller__c = ResellerAct.Id;              
                }
               If (GetDistributor.AccountId <> NULL )
                {
                DistributorAct = [ SELECT Id FROM Account WHERE ID = :GetDistributor.AccountId Limit 1];
                TempAsset.Distributor__c = DistributorAct.Id;
                }
               If ( GetOpportunity.Opportunity__c <> NULL )
                {
                Oppt = [SELECT Id FROM Opportunity WHERE ID = :GetOpportunity.Opportunity__c Limit 1];
                TempAsset.Existing_Opportunity__c = Oppt.Id;
                }               
              TempAsset.Incumbent_Reseller__c = IncumbentReseller;
              TempAsset.Education__c = Education;
              //TempAsset.Expiry_Date__c = GetExpireDate.Expire_Date__c;
              TempAsset.Expiry_Date__c= maxDate;
             
              TempAsset.New_Opportunity__c = GetNewOpportunity.New_Opportunity__c;
              TempAsset.Expiry_Term__c = ExpireTerms;
             
                /* Insert Bundel Checkbox Value */               
                if (this.selectedContactIds2.contains(Act.Id)){
                    bundsprt=true;
                }
                else {
                    bundsprt=false;
                }
   
               
                TempAsset.Bundle_Support__c = bundsprt;
              System.debug('== Bundle Value is: ' + bundsprt);
             
                             //Add the selected Assets to the List
              TempAssetList.add(TempAsset);
            }
           
        Insert TempAssetList; 
       
        setCon.setpageNumber(currentPageNumber);
       
    } 
   
    /*
    *   return whether previous page exists
    */
    public Boolean getHasPrevious(){
       
        return this.setCon.getHasPrevious();
       
    }

   
   
    /*
    *   return whether next page exists
    */
    public Boolean getHasNext(){
       
        return this.setCon.getHasNext();
   
    }
   
   
    /*
    *   return page number
    */
    public Integer getPageNumber(){
       
        return this.setCon.getPageNumber();
       
    }
   
   
    /*
    *    return total pages
    */
    Public Integer getTotalPages(){
   
        Decimal totalSize = this.setCon.getResultSize();
        Decimal pageSize = this.setCon.getPageSize();
       
        Decimal pages = totalSize/pageSize;
       
        return (Integer)pages.round(System.RoundingMode.CEILING);
    }
   
   
  
   
    /*
    *   helper class that represents a row
    */
    public with sharing class CCWRowItem{
       
        public Asset tContact{get;set;}
        public Boolean IsSelected{get;set;}
        public Boolean BundelSelected{get;set;}
        
        public CCWRowItem(Asset c){
            this.tContact=c;           
            this.IsSelected=false;
            this.BundelSelected=false;
        }
       
    }
 
      
    
   
}
Swati GSwati G
Do you want to only allow 10 pages to be shown or 10 records per page?
Sudhir_MeruSudhir_Meru
I want to show 10 records per page and based on number of records display that many pages. 
Sudhir_MeruSudhir_Meru
Hi Swati, 

  Do you have any suggest Please

Thanks
Sudhir