1

I am prepared to be flamed for asking such a newbie question (which is similar to others) but I'll suffer the shame if I can get this resolved. Since my background is mostly procedural code, I'm studying SalesForce's "VisualForce in Practice" and am coding as I go. In Chapter 4 (list controllers), they have me list contacts and (supposedly) have Next/Previous buttons appear.

When I code the following, no buttons appear. I know that the rendered is evaluating as false (because the buttons don't appear) and suspect that the code doesn't exist for HasPrevious/HasNext. In the examples I've seen (Display more than 3000 records in a VF page and http://forceguru.blogspot.in/2011/04/pagination-in-salesforce.html), they have a controller which has code for HasPrevious/HasNext. The book discusses a standardSetController but doesn't prompt me to write any code for it.

If I'm using a standardController, then shouldn't this code exist? I'm not supposed to write an extension for this, am I? If not, why do the buttons not show?

Thanks.

Mike

Code:

<apex:page standardController="Contact" recordSetVar="contacts">
    <apex:form >
        <apex:pageBlock title="Simple Contact List">
            <apex:pageBlockTable value="{!contacts}" var="c" rows="5">
                <apex:column value="{!c.Id}"/>
                <apex:column value="{!c.FirstName}"/>
                <apex:column value="{!c.LastName}"/>
                <apex:column value="{!c.Email}"/>
             </apex:pageBlockTable>
             <apex:pageBlock > 
                 <apex:pageBlockButtons location="bottom">
                     <apex:commandLink action="{!Previous}" value="Previous Page" rendered="{!HasPrevious}"/>
                     <apex:commandLink action="{!Next}" value="Next Page" rendered="{!HasNext}"/>
                 </apex:pageBlockButtons>
            </apex:pageBlock>
         </apex:pageBlock>
     </apex:form>
</apex:page>
3

There are two types of standard controller:

and specifying a recordSetVar in the apex:page causes the second type to be used. Listed in its available methods are getHasNext and getHasPrevious and these can be referenced without the "get".

When I paste your page into an org I do see the previous/next links. I get 20 contacts at a time - if you have less than 20 contacts the pagination may be automatically switched off.

To start with you do not need to write a controller extension: that is where you may later add custom behaviour.

| improve this answer | |
  • To anyone who reads my question, I apologize for not doing the most basic test of all--counting how many contacts I have. Sigh. I have exactly 20. :) Mea maxima culpa. @Keith C, I do thank you for the explanation about recordsetVar invoking the standardSetController. Now I understand how and why it get used. Thanks for the clarification. – Mike Jun 19 '14 at 0:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.