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
eriktowneriktown 

Displaying more than 20 Contacts with the Contacts standard controller

Hello folks,

 

I'm using the Contacts standard controller to display a list of the user's contacts; the user then can click a button to select a particular contact. But I'm finding that the controller list method isn't allowing me to display more than 20 contacts at once. Is there any way to make it list all contacts, instead of the first 20? Failing that, is there a way to display the next section of the list?

 

Thank you in advance!

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Presumably you are using the standard list controller?  That being the case you have built-in support for pagination, e.g.

 

<apex:commandLink action="{!previous}">Previous</apex:commandlink>
<apex:commandLink action="{!next}">Next</apex:commandlink>

 If you want to change the number of records displayed on a page, you'll need to set the pagesize on the standard controller, which probably means an extension controller.

All Answers

bob_buzzardbob_buzzard

Presumably you are using the standard list controller?  That being the case you have built-in support for pagination, e.g.

 

<apex:commandLink action="{!previous}">Previous</apex:commandlink>
<apex:commandLink action="{!next}">Next</apex:commandlink>

 If you want to change the number of records displayed on a page, you'll need to set the pagesize on the standard controller, which probably means an extension controller.

This was selected as the best answer
eriktowneriktown

Thank you very much for your response, Bob.

 

I've already got an extension controller for that particular page due to another operation I'm performing. But I'm not sure how to set the page size - I see that there is a setPageSize method on the StandardSetController, but I can't find one for the Contacts controller.  Do I need to instantiate a StandardSetController? If so how do I make it apply to the Contacts controller I'm already using?

 

 

bob_buzzardbob_buzzard

Are you using a standard list controller or a standard controller?  I'm assuming the former given the 20 per page.

 

In that case, your extension controller should have a constructor that takes ApexPages.StandardSetController as a parameter - do you have one of those?

 

eriktowneriktown

Oh! You're right, I do. So I'd just call setPageSize on that?

bob_buzzardbob_buzzard

That's my understanding.  Let us know if that does it :)

eriktowneriktown

I am pleased to announce that it works just as expected. :)

 

I don't suppose you know if there is a way to supress the "Previous" link if we're on the first page of the list?

bob_buzzardbob_buzzard

The standard controller has a getPageNumber that returns 1 if you are on the first page.

 

Thus you should be able to have something like:

 

<apex:commandLink action="{!previous}" rendered="{!NOT(pageNumber==1)}">Previous</apex:commandlink>