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
Greg DiercksGreg Diercks 

Standard List Controller exercise

I'm finding the directions a little vague as to *exactly* where to plug in the various little sections of code that ultimately give us pagination.  I think I'm just plugging stuff in the wrong location.

I think it would be helpful to have included what the final page should have looked like.

Would someone please post it here so I can see what the heck I'm doing wrong?

Thanks!
Jai ChaturvediJai Chaturvedi
Hi,

To associate a page with the standard list controller for accounts, use the following markup:
<apex:page standardController="Account" recordSetVar="accounts">

Standard list controller provides additional four pagination actions. Those are first, last, next and previous.

Copy paste this code in your page.
<apex:page standardController="Account" recordSetVar="accounts">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!Accounts}" var="a">
<apex:column headerValue="Account Name">
<apex:outputField value="{!a.name}"/>
</apex:column>
</apex:pageBlockTable>

<!-- pagination actions supported by standard list controller -->
<apex:pageBlockButtons >
<apex:commandButton value="First" action="{!first}"/>
<apex:commandButton value="Last" action="{!last}"/>
<apex:commandButton value="Next" action="{!next}"/>
<apex:commandButton value="previous" action="{!previous}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>



Hope this helps you out.

Thanks
Jai
Greg DiercksGreg Diercks
Thanks, that helps...
Jai ChaturvediJai Chaturvedi
Hi,

Can you please mark that as solution.I will really appreciate that.

Thanks
Jai
William TranWilliam Tran
Gregory,

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you. 

In addition to 
first, last, next and previous.
you can go to page a certain page number, get total results, etc.

Refer to this document for more info:

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_ApexPages_StandardSetController_methods.htm

Thanks
Rachel_NatikRachel_Natik
I think what he's asking with and what I am struggling with as well is that they give you a pices of code and then more peices to put within that. I copied their instructions and it is not working. It would be helpful if they gave you what the final code should look like.
Sandeep BhanotSandeep Bhanot

Hi Rachel,
Its a good point that we should add the final VF markup at the end of the unit. I'll add that to our list of content updates to make. In the meantime, here is what the final markup should look like. Hope this helps!

Sandeep

 

<apex:page standardController="Contact" recordSetVar="contacts">
    <apex:form>

        <apex:pageBlock title="Contacts List" id="contacts_list">
        
            Filter: 
            <apex:selectList value="{! filterId }" size="1">
                <apex:selectOptions value="{! listViewOptions }"/>
                <apex:actionSupport event="onchange" reRender="contacts_list"/>
            </apex:selectList>

            <!-- Contacts List -->
            <apex:pageBlockTable value="{! contacts }" var="ct">
                <apex:column value="{! ct.FirstName }"/>
                <apex:column value="{! ct.LastName }"/>
                <apex:column value="{! ct.Email }"/>
                <apex:column value="{! ct.Account.Name }"/>
            </apex:pageBlockTable>

            <!-- Pagination -->
           <table style="width: 100%"><tr>

                 <td>
                     Page: <apex:outputText  value=" {!PageNumber} of {! CEILING(ResultSize / PageSize) }"/>
                 </td>            

                <td align="center">
                      <!-- Previous page -->
                          <!-- active -->
                        <apex:commandLink action="{! Previous }" value="« Previous"  rendered="{! HasPrevious }"/>
                              <!-- inactive (no earlier pages) -->
                         <apex:outputText style="color: #ccc;" value="« Previous"  rendered="{! NOT(HasPrevious) }"/>

                         &nbsp;&nbsp;  

                        <!-- Next page -->
                        <!-- active -->
                        <apex:commandLink action="{! Next }" value="Next »"  rendered="{! HasNext }"/>
                       <!-- inactive (no more pages) -->
                       <apex:outputText style="color: #ccc;" value="Next »"  rendered="{! NOT(HasNext) }"/>
                 </td>
    
                 <td align="right">
                     Records per page:
                      <apex:selectList value="{! PageSize }" size="1">
                             <apex:selectOption itemValue="5" itemLabel="5"/>
                             <apex:selectOption itemValue="20" itemLabel="20"/>
                             <apex:actionSupport event="onchange" reRender="contacts_list"/>
                     </apex:selectList>
                 </td>
 
              </tr></table>
        
            
        </apex:pageBlock>

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

 
Greg DiercksGreg Diercks
This is *really* what I was looking for. Thanks!!!!!
Rachel_NatikRachel_Natik
Terrific! My mistake was adding the pagination right below this line. Can you please fix the content to reflect tht it should be added after the ENTIRE section, not just this line: * *