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
bhanu_prakashbhanu_prakash 

issue with pagnation on vf page

Hi team,

I have tried to design vf page to fetch list of accounts with pagination. Unable to pull account information .
vf page
<apex:page standardController="Account" recordSetVar="Accounts" extensions="PaginationAcc" lightningStylesheets="true" showHeader="false" sidebar="false" tabStyle="Account">
  <apex:form >
      <apex:pageBlock title="Accounts">
          <apex:pageBlockTable value="{!acList}" var="ac"  id="pgTaAcc">
              <apex:column width="10px">
                    <input type="radio" name="group1" />
                    <apex:actionSupport event="onclick" action="{!showContact}" ReRender="lab" >
                        <apex:param assignTo="{!accId}" name="accname" value="{!ac.id}"/>
                    </apex:actionSupport>
                </apex:column>
              <apex:column >
                 <apex:facet name="header">AccountName</apex:facet><apex:outputField value="{!ac.name}" />
              </apex:column>
              <apex:column >
                  <apex:facet name="header">Type</apex:facet><apex:outputField value="{!ac.Type}"/>
              </apex:column>
              <apex:column >
                  <apex:facet name="header">BillingCity</apex:facet><apex:outputField value="{!ac.BillingCity}"/>
              </apex:column>
              <apex:column >
                  <apex:facet name="header">BillingState</apex:facet><apex:outputField value="{!ac.BillingState}"/>
              </apex:column>
              <apex:column >
                  <apex:facet name="header">BillingCountry</apex:facet><apex:outputField value="{!ac.BillingCountry}"/>
              </apex:column>
          </apex:pageBlockTable>
          
          <apex:pageBlock id="lab">
              <apex:outputPanel rendered="{!conList.size == 0}">
                  <b>No records for this account</b>
              </apex:outputPanel>
              
              <apex:outputPanel rendered="{!conList.size != 0}">  
                  <apex:pageBlock title="Contacts">
                      <apex:pageBlockTable value="{!conList}" var="cn">
                          <apex:column >
                              <apex:facet name="header">First Name</apex:facet><apex:outputField value="{!cn.firstname}" />
                          </apex:column>
                          <apex:column >
                              <apex:facet name="header">Last Name</apex:facet><apex:outputField value="{!cn.lastname}" />
                          </apex:column>                      
                      <apex:column ><apex:facet name="header">Title</apex:facet><apex:inputField value="{!cn.Title}" /></apex:column>                                                                                           
                      <apex:column ><apex:facet name="header">Leadsource</apex:facet><apex:inputField value="{!cn.leadsource}"/></apex:column>                      
                      <b><apex:param name="em" value="{!eml}" assignTo="{!em}"/></b>
                  </apex:pageBlockTable>
                  </apex:pageBlock>
          </apex:outputPanel>          
          <apex:commandButton value="Save" action="{!save}" reRender="lan"/>          
          </apex:pageBlock>
          <apex:pageBlockButtons >
              <apex:commandButton value="First" action="{!first}"/> 
              <apex:commandButton value="Previous" action="{!previous}"/>
              <apex:commandButton value="Next" action="{!next}" reRender="pgTaAcc,lab" />
              <apex:commandButton value="Last" action="{!last}" reRender="pgTaAcc,lab"/> 
           <!-- <apex:outputText >{!(setcon.pageNumber * size)+1-size}   -    {!IF((setcon.pageNumber * size)>noOfRecords, noOfRecords,(setcon.pageNumber * size))} of {!noOfRecords}</apex:outputText> -->
          </apex:pageBlockButtons> 
      </apex:pageBlock>
  </apex:form>
</apex:page>

class
 
global class PaginationAcc {
    public PaginationAcc(ApexPages.StandardSetController setcon) { }    
    public List<Account> acList {get;set;}
    public List<Contact> conList {get;set;}   
    public string accId {get;set;}
    public string eml {get;set;}
    Public Integer noofRecords {get; set;}
    public integer size {get; set;}
    
    public Apexpages.standardsetController setcon{
        get{
            if(setCon == null){
                size = 10;
                String queryString = 'Select Name, Type, BillingCity, BillingState, BillingCountry from Account order by Name';
                setcon = new apexpages.standardsetController(Database.getquerylocator(queryString));
                setcon.setpagesize(size);
                noofRecords = setcon.getResultsize();
            }
            return setcon;
        }
         set;
    }
    Public list<Account> getAccounts(){
        list<Account> acclist = new list<Account>();
         for(Account ac : (list<Account>)setcon.getrecords()){
             acclist.add(ac);
         }
        return accList;
       
      
    }
   
    Public PageReference Refresh(){
       
        setcon=null;
        getAccounts();
        setcon.setpageNumber(1);
       
        return null;
    }
    
    public void showContact()
    {
        conList = new List<Contact>();
        for(contact c : [select id,firstname,lastname,Title,leadsource from contact where accountid =: accId])
        {
            conList.add(c);
        }      
    }
    
    public void save()
    {
        update conList;
    }
}
Thanks for advance
Best Answer chosen by bhanu_prakash
bhanu_prakashbhanu_prakash
changed into 
<apex:commandButton value="First" action="{!setCon.first}"/> 
                <apex:commandButton value="Previous" action="{!setCon.previous}"/>
                <apex:commandButton value="Next" action="{!setCon.next}"/>
                <apex:commandButton value="Last" action="{!setCon.last}"/>
issue got resloved :)

All Answers

GauravendraGauravendra
Hi Bhanu,

As you are using standard list controller (by setting recordSetVar), in pageblocktable pass value attribute as {!Accounts}.
<apex:pageBlockTable value="{!Accounts}" var="ac" id="pgTaAcc">

Hope this helps.
bhanu_prakashbhanu_prakash
Iam able to see accounts but pagination is not working 
bhanu_prakashbhanu_prakash
changed into 
<apex:commandButton value="First" action="{!setCon.first}"/> 
                <apex:commandButton value="Previous" action="{!setCon.previous}"/>
                <apex:commandButton value="Next" action="{!setCon.next}"/>
                <apex:commandButton value="Last" action="{!setCon.last}"/>
issue got resloved :)
This was selected as the best answer