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
Abhishek Singh 88Abhishek Singh 88 

next link navigation is not working in pagination

here i have a table
User-added image
so after clicking on customer id i have to show related records.so for that i have implemented pagination.
here is my apex class:
public ApexPages.StandardSetController setCon //pagignation for customer incident
                     {
                       get{
                        if(setcon==null)
                          {
                             size=10;
                string queryString = 'select id,Name,BMCServiceDesk__shortDescription__c,PHS_Category__c,PHS_Sub_Category__c,BMCServiceDesk__FKStatus__c from BMCServiceDesk__Incident__c where account__r.customerId__c=:currentSiteCust';
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
                setCon.setPageSize(size);
                noOfRecords = setCon.getResultSize();  
                         }
                          return setCon;
                       }set;
                    }
                   public Boolean hasNext {
                                get {
                                        return setCon.getHasNext();
                                        }
                                               set;
                                     }
                    public void first()
                     {
                            setcon.first();
                    }
                    public void last()
                     {
                            setcon.last();
                    }
                    public void previous()
                     {
                            setcon.previous();
                    }
                  public void next()
                     {
                            setcon.next();
                    }
 public pagereference searchincidents()//getting records from setcon
                        {   
                         for(BMCServiceDesk__Incident__c  a : (List<BMCServiceDesk__Incident__c >)setCon.getRecords())
                           {
                              custincidentLst.add(a);
                           }
                           return null;
                          }

here is my VF page
<apex:pageBlock title="Incidents" rendered="{!showIncidents}" id="pb">
<apex:pageblocktable value="{!custincidentLst}" var="inci">
<apex:column headerValue="Name">                    
                     <apex:outputField value="{!inci.Name}"/>
                 </apex:column>
</apex:pageblocktable>
<apex:panelGrid columns="7">
               <apex:commandButton status="fetchStatus" reRender="pb" value="|<" action="{!first}" disabled="{!!setcon.hasPrevious}" title="First Page"/>
                 <apex:commandButton status="fetchStatus" reRender="pb" value="<" action="{!previous}" disabled="{!!setcon.hasPrevious}" title="Previous Page"/>
                 <apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!next}" disabled="{!!setcon.hasnext}" title="Next Page"/>
                 <apex:commandButton status="fetchStatus" reRender="pb" value=">|" action="{!last}" disabled="{!!setcon.hasnext}" title="Last Page"/>
                <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,(setCon.pageNumber * size))} of {!noOfRecords}</apex:outputText>
                 <apex:outputPanel style="color:#4AA02C;font-weight:bold">
                    <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
                </apex:outputPanel>
                </apex:panelGrid>
</apex:pageblock>

But the problem is,i am not able to refresh the fresh data,means when i am clicking on nex button it showing only those old records.
any suggestion will be appriciated. 
Best Answer chosen by Abhishek Singh 88
karthikeyan perumalkarthikeyan perumal
Hello Abhishek, 

Use below code as follow. 

Step1: Creaet class with this code: 
 
public class CategoryWrapper {

    public Boolean checked{ get; set; }
    public BMCServiceDesk__Incident__ct BMC { get; set;}

    public CategoryWrapper(){
        BMC = new BMCServiceDesk__Incident__c();
        checked = false;
    }

    public CategoryWrapper(BMCServiceDesk__Incident__c B){
        BMC = B;
        checked = false;
    }

     
}
Setp 2:  Create below code with this code
 
public with sharing class PagingController {

    List<categoryWrapper> categories {get;set;}

    
    public ApexPages.StandardSetController con {
        get {
            if(con == null) {
                string queryString = 'select id,Name,BMCServiceDesk__shortDescription__c,PHS_Category__c,PHS_Sub_Category__c,BMCServiceDesk__FKStatus__c from BMCServiceDesk__Incident__c where account__r.customerId__c=:currentSiteCust Limit 1000';
            
                con = new ApexPages.StandardSetController(Database.getQueryLocator([queryString]));
                
                con.setPageSize(10);
            }
            return con;
        }
        set;
    }

     
    public List<categoryWrapper> getCategories() {
        categories = new List<categoryWrapper>();
        for (BMCServiceDesk__Incident__c  category : (List<BMCServiceDesk__Incident__c>)con.getRecords())
            categories.add(new CategoryWrapper(category));

        return categories;
    }

     
     public PageReference process() {
         for (CategoryWrapper cw : categories) {
             if (cw.checked)
                 ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,cw.BMC.Name));
         }
         return null;
     }

     
    public Boolean hasNext {
        get {
            return con.getHasNext();
        }
        set;
    }

     
    public Boolean hasPrevious {
        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();
     }

      
     public void cancel() {
         con.cancel();
     }
}

Step 3: Create Visual force page with following code.
 
<apex:page controller="PagingController">  
  <apex:form >
    <apex:pageBlock title="Paging">     
      <apex:pageMessages />

      <apex:pageBlockSection title="Category Results -  Page #{!pageNumber}" columns="1">
        <apex:pageBlockTable value="{!categories}" var="c">
          <apex:column value="{!c.BMC.Name}" headerValue="Name"/>
        </apex:pageBlockTable>
      </apex:pageBlockSection>
    </apex:pageBlock>

    <apex:panelGrid columns="4">
    <apex:commandLink action="{!first}">First</apex:commandlink>
    <apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandlink>
    <apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandlink>
    <apex:commandLink action="{!last}">Last</apex:commandlink>
    </apex:panelGrid>

  </apex:form>
</apex:page>

Hope this will solve your Issue. 
Make it best if its work for you. 

Thanks
karthik

 

All Answers

karthikeyan perumalkarthikeyan perumal
Hello Abhishek, 

Use below code as follow. 

Step1: Creaet class with this code: 
 
public class CategoryWrapper {

    public Boolean checked{ get; set; }
    public BMCServiceDesk__Incident__ct BMC { get; set;}

    public CategoryWrapper(){
        BMC = new BMCServiceDesk__Incident__c();
        checked = false;
    }

    public CategoryWrapper(BMCServiceDesk__Incident__c B){
        BMC = B;
        checked = false;
    }

     
}
Setp 2:  Create below code with this code
 
public with sharing class PagingController {

    List<categoryWrapper> categories {get;set;}

    
    public ApexPages.StandardSetController con {
        get {
            if(con == null) {
                string queryString = 'select id,Name,BMCServiceDesk__shortDescription__c,PHS_Category__c,PHS_Sub_Category__c,BMCServiceDesk__FKStatus__c from BMCServiceDesk__Incident__c where account__r.customerId__c=:currentSiteCust Limit 1000';
            
                con = new ApexPages.StandardSetController(Database.getQueryLocator([queryString]));
                
                con.setPageSize(10);
            }
            return con;
        }
        set;
    }

     
    public List<categoryWrapper> getCategories() {
        categories = new List<categoryWrapper>();
        for (BMCServiceDesk__Incident__c  category : (List<BMCServiceDesk__Incident__c>)con.getRecords())
            categories.add(new CategoryWrapper(category));

        return categories;
    }

     
     public PageReference process() {
         for (CategoryWrapper cw : categories) {
             if (cw.checked)
                 ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,cw.BMC.Name));
         }
         return null;
     }

     
    public Boolean hasNext {
        get {
            return con.getHasNext();
        }
        set;
    }

     
    public Boolean hasPrevious {
        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();
     }

      
     public void cancel() {
         con.cancel();
     }
}

Step 3: Create Visual force page with following code.
 
<apex:page controller="PagingController">  
  <apex:form >
    <apex:pageBlock title="Paging">     
      <apex:pageMessages />

      <apex:pageBlockSection title="Category Results -  Page #{!pageNumber}" columns="1">
        <apex:pageBlockTable value="{!categories}" var="c">
          <apex:column value="{!c.BMC.Name}" headerValue="Name"/>
        </apex:pageBlockTable>
      </apex:pageBlockSection>
    </apex:pageBlock>

    <apex:panelGrid columns="4">
    <apex:commandLink action="{!first}">First</apex:commandlink>
    <apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandlink>
    <apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandlink>
    <apex:commandLink action="{!last}">Last</apex:commandlink>
    </apex:panelGrid>

  </apex:form>
</apex:page>

Hope this will solve your Issue. 
Make it best if its work for you. 

Thanks
karthik

 
This was selected as the best answer
karthikeyan perumalkarthikeyan perumal
Hello Abhishek, 

According to your code you have to add one more methid in you controller called "referesh like below invoke the method using command button manually. that referesh your list and fetch new created records.

 public pageReference Reload() {
        setCon = null;
        getAccounts();
        setCon.setPageNumber(1);
        return null;
    }


in VF page

<apex:commandButton status="UpdateRecords" reRender="pb" value="Reload" action="{!Reload}"/>

Hope this will help you. 

Mark Best ANSWER if its work for you. 

Thansk
karthik
 
Abhishek Singh 88Abhishek Singh 88
Thanks Karthik it worked.
Abhishek Singh 88Abhishek Singh 88
It worked for one time.when refresh my vf page,it working as priviously it was..
karthikeyan perumalkarthikeyan perumal
Post your VF page display before and after when you hit the next button. also add what behaviour you need when you hit next link. 
 
karthikeyan perumalkarthikeyan perumal
Post your VF page display before and after when you hit the next button. also add what behaviour you need when you hit next link. 
 
Abhishek Singh 88Abhishek Singh 88
here is my vf page.
<apex:pageBlock title="Incidents" rendered="{!showIncidents}" id="pb">
         <apex:pageblockSection >
          <apex:outputLabel >List of Incident related to Customer Id:{!currentSiteCust}</apex:outputLabel>
          </apex:pageblockSection>
             <apex:commandlink action="{!newIncidentLink}" target="_balank" >
          <apex:commandButton value="New Incident" id="newIncident"/><br />
           </apex:commandlink>
              <div style="overflow: scroll;height: 200px;">
                  <apex:pageBlockTable value="{!Categories}" var="inci">
                   <apex:column headerValue="Incident #">
            <apex:outputLink value="https://bmcservicedesk.cs15.visual.force.com/apex/BMCServiceDesk__RemedyforceConsole?record_id={!inci.BMC.id}&objectName=Incident__c" target="_blank">{!inci.BMC.Name}</apex:outputLink>
                   </apex:column>
                    <apex:column headerValue="Name">                    
                     <apex:outputField value="{!inci.BMC.Name}"/>
                 </apex:column> 
</apex:pageblocktable>
<apex:panelGrid columns="7">
               <apex:commandButton status="fetchStatus" reRender="pb" value="|<" action="{!first}" disabled="{!!setcon.hasPrevious}" title="First Page"/>
                 <apex:commandButton status="fetchStatus" reRender="pb" value="<" action="{!previous}" disabled="{!!setcon.hasPrevious}" title="Previous Page"/>
                 <apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!next}" disabled="{!!setcon.hasnext}" title="Next Page"/>
                 <apex:commandButton status="fetchStatus" reRender="pb" value=">|" action="{!last}" disabled="{!!setcon.hasnext}" title="Last Page"/>
                <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,(setCon.pageNumber * size))} of {!noOfRecords}</apex:outputText>
                 <apex:outputPanel style="color:#4AA02C;font-weight:bold">
                    <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
                </apex:outputPanel>
                </apex:panelGrid>
</apex:pageblock>

here is table
User-added image
so there are total 14 records,10 is page size.
but when i am clicking on nex button 
it showing
User-added image
but records are not refreshing.
karthikeyan perumalkarthikeyan perumal
Hello, 

Check the Div is not having the close tag </div>
also share the Controller method for next()

Thanks
karthik
 
Abhishek Singh 88Abhishek Singh 88
here is set controller
public ApexPages.StandardSetController setCon //pagignation for customer incident
                     {
                       get{
                        if(setcon==null)
                          {
                             size=10;
                string queryString = 'select id,Name,BMCServiceDesk__shortDescription__c,PHS_Category__c,PHS_Sub_Category__c,BMCServiceDesk__FKStatus__c from BMCServiceDesk__Incident__c where account__r.customerId__c=:currentSiteCust limit 1000';
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
                setCon.setPageSize(size);
                noOfRecords = setCon.getResultSize();  
                         }
                          return setCon;
                       }set;
                    }
                    public List<categoryWrapper> getCategories() 
                       {
                            categories = new List<categoryWrapper>();
                            for (BMCServiceDesk__Incident__c  category : (List<BMCServiceDesk__Incident__c>)setcon.getRecords())
                            categories.add(new CategoryWrapper(category));
                                      return categories;
                     }
                   public Boolean hasNext {
                                get {
                                        return setCon.getHasNext();
                                        }
                                               set;
                                     }
                    public void first()
                     {
                            setcon.first();
                    }
                    public void last()
                     {
                            setcon.last();
                    }
                    public void previous()
                     {
                            setcon.previous();
                    }
                  public void next()
                     {
                            setcon.next();
                    }

and i checked div tag,it is closed,it was mistake in pating code.
karthikeyan perumalkarthikeyan perumal
Hello, 

I used your code just changed the Object name its working Perfect.  consider those images. 

User-added image
User-added image

Thanks
karthikeyan perumalkarthikeyan perumal
also check the rerender area "pb" also check the this method in controller "newIncidentLink" is there any pagereference is there

 
Abhishek Singh 88Abhishek Singh 88
yes there is pagereference in "newIncidentLink".