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
ajay ambatiajay ambati 

Issue in pagination

hi
Iam using custom controller my requriment is when iam entering feilds in vfpage using input componnent record has to be saved to database and fetch all the details records from database and didplay in pageblock table.And in same page iam included pagination and when iam click on firstpage it has to be display first 10 records from database and secondpage next 10 records and lastpage remaining records so i tried for below code and page records are displaying after saving but not working pagination part here below you find my code

public with sharing class task2Pagination {
  
  public ajay_ambati_2__Candidate1__c can{get;set;}
  public List<ajay_ambati_2__Candidate1__c> canlst {get;set;}
  public boolean Popup {get; set;}
  Public Integer noOfRecords {get; set;}
  Public Integer size {get;set;} 
  
   
  public task2Pagination (){
        can = new ajay_ambati_2__Candidate1__c();
    
        canlst = new list<ajay_ambati_2__Candidate1__c>();
        canlst = [Select Name,ajay_ambati_2__Age__c,ajay_ambati_2__Gender__c,ajay_ambati_2__Salary__c from ajay_ambati_2__Candidate1__c Order By Name];
        
    }
  
    
    public void closePopup() {        
        Popup  = false;    
    }     
       
    
  public PageReference Save() {
        insert can;
   
      
         Popup  = true;
       
        return null;
       
    }
    
    
  /* public PageReference fetchDetails(){
   
     empList = [Select Name,ajay_ambati_2__Age__c,ajay_ambati_2__Gender__c,ajay_ambati_2__Salary__c from ajay_ambati_2__Candidate1__c Order By Name];
      System.debug('Employee details'+empList );
       return null;
   
   }*/
   
    public ApexPages.StandardSetController Con {
        get{
            if(Con == null){
                size = 10;
                string queryString = 'Select Name, ajay_ambati_2__Age__c,ajay_ambati_2__Gender__c,ajay_ambati_2__Salary__c from ajay_ambati_2__Candidate1__c order by Name';
                Con = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
                Con.setPageSize(size);
                // System.debug('<<size>>'+size);
                 noOfRecords = Con.getResultSize();
                    System.debug('<<NoOf Records>>'+noOfRecords);
            }
            return Con;
        }set;
    }
     
   /* Public List<Eployee__c> getEployees(){
        List<Eployee__c> empList = new List<Eployee__c>();
        for(Eployee__c a : (List<Eployee__c>)setCon.getRecords())
            empList.add(a);
        empList.sort();
        return empList;
    }*/
     
   /* public pageReference refresh() {
        setCon = null;
        getEployees();
        setCon.setPageNumber(1);
        return null;
    }*/
     
    public Boolean hasNext1 {
        get {
            return Con.getHasNext();
        }
        set;
    }
    public Boolean hasPrevious1 {
        get {
            return Con.getHasPrevious();
        }
        set;
    }
  
    public Integer pageNumber {
        get {
            return Con.getPageNumber();
        }
        set;
    }
  
    public void first() {
        Con.first();
    }
  
    public void last() {
        Con.last();
    }
  
    public void previous() {
        Con.previous();
    }
  
    public void next() {
        Con.next();
    }

}

______________________________DONT CONFUSE IAM USING SLDC IN VISUAL FORCE PAGE _______________________
<apex:page showHeader="false" sidebar="false" standardStylesheets="true" Controller="task2Pagination" >
  <apex:form >
    <apex:pageMessages />
    <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
        <head>
            <apex:slds />
        </head>
        <body class="slds-scope" >
        
                <div class="slds-media__figure" >
    <svg aria-hidden="true" class="slds-icon slds-icon-standard-contact">
        <use xlink:href="{!URLFOR($Asset.SLDS, '/assets/icons/standard-sprite/svg/symbols.svg#contact')}"></use>
    </svg> EDIT CANDIDATE
   
</div>&nbsp;&nbsp;&nbsp;



<div class="slds-form-element slds-hint-parent" scope="col">
  
    <span class="slds-form-element__label"><strong></strong>Name</span>
    <div class="slds-form-element__control">
       <apex:inputField styleClass="slds-input" value="{!can.Name}" style="width:57%; line-height:1.875em;" />
     
    </div>
</div>


 <div class="slds-form-element slds-hint-parent"  >
    <span class="slds-form-element__label"><strong></strong>Gender</span>
    <div class="slds-form-element__control" >
         
       <apex:inputField styleClass="slds-input" value="{!can.Gender__c}" style="width:10% ; line-height:75em;"/>
   </div>   
</div>

 <div class="slds-form-element slds-hint-parent" >
    <span class="slds-form-element__label"><strong></strong>Age</span>
    <div class="slds-form-element__control" >

       <apex:inputField styleClass="slds-input" value="{!can.Age__c}"  style="width:57%; line-height:1.875em;"/>
   </div>
</div>


 <div class="slds-form-element slds-hint-parent" >
    <span class="slds-form-element__label"><strong></strong>Salary</span>
    <div class="slds-form-element__control" >
         
       <apex:inputField styleClass="slds-input" value="{!can.Salary__c}" style="width:57%; line-height:1.875em;"/>
   </div>
</div>


<div class="slds-p-horizontal--small slds-m-top--medium slds-size--1-of-1 slds-align--absolute-center">
    <apex:commandButton styleClass="slds-button slds-button--brand" value="Save" action="{!save}" />
</div>
       
       
<apex:outputPanel id="myPanel">
        <table cellspacing="3" cellpadding="3" class="slds-table slds-table_bordered slds-table_cell-buffer" styleclass="">
                            <tr >
                                
                                
                                <th width="30%"> Name</th>
                                <th width="15%"> Gender</th>
                                <th width="30%">Age</th>
                                <th width="30%">Salary</th>
                                
                            </tr>
                          <apex:repeat value="{!canlst}" var="a">
                           
                                <tr >
                                                                   
                                    <td >                                        
                                        <apex:outputField value="{!a.Name}" />
                                    </td>
                                    <td>                                        
                                        <apex:outputField value="{!a.Age__c}" />
                                    </td>
                                    <td >                                       
                                       <apex:outputField value="{!a.Gender__c}" />
                                    </td>
                                     <td >                                       
                                       <apex:outputField value="{!a.Salary__c}" />
                                    </td>
                                    
                                </tr></apex:repeat>
                        </table>
     </apex:outputPanel>
     
     
<div class="slds-p-horizontal--small slds-m-top--medium slds-size--1-of-1 slds-align--absolute-center">
    <apex:commandButton styleClass="slds-button slds-button--brand" value="firstpage" action="{!first}" />
    <apex:commandButton styleClass="slds-button slds-button--brand" value="lastpage" action="{!last}"/>
    <apex:commandButton styleClass="slds-button slds-button--brand" value="previouspage" action="{!previous}" />
    <apex:commandButton styleClass="slds-button slds-button--brand" value="nextpage" action="{!next}" />
   
</div>
      
       
        </body>
    </html>
   </apex:form>
</apex:page>
 
RakeshRakesh (Salesforce Developers) 
Hi Ajay,

Please go through the below links, it may help you to solve this. Use the sample codes and modify it according to your requirement.  Please mark it as solved if this reply was helpful.

Thanks,
Rakesh