I recently found out that the StandardSetController can't be used with any of the History records such as MyCustomObject__History. The exception I got was:

List controllers are not supported for MyCustomObject__History

The thing is, given this limitation, what would be the best solution to implement pagination? The most inmediate one would be to implement my own pagination solution, but I'm wondering if Salesforce has any other options.

  • No, you'll need to use your own pagination logic. I think I might have an example laying around somewhere.
    – sfdcfox
    Sep 5 '17 at 15:59
  • @sfdcfox I know it's another question but... do you know why they aren't supported by any chance? Sep 5 '17 at 16:01
  • They don't tell us, but I'd guess it's because they don't want to introduce cursors for those objects, probably as a matter of performance.
    – sfdcfox
    Sep 5 '17 at 16:31
  • @sfdcfox thanks! Submited the answer with your snippet. It's a pity it's the only solution and SF doesn't have any other alternatives. Sep 6 '17 at 11:32

After doing a bit of research, the best approach (and maybe the only one?) is what @sfdcfox suggested: create the pagination logic in the controller.

The snippet he included was:

public class ServerSide50KPagination {
    Id[] recordIds;
    public Integer maxPage { get; set; }
    public Integer pageNumber { get; set; }
    public Integer pageSize { get; set; }
    public Account[] records { get; set; }

    public ServerSide50KPagination() {
        recordIds = new Id[0];
        for(Account record: [SELECT Id FROM Account ORDER BY Name]) {
        pageSize = 10;
        maxPage = (recordIds.size()+(pageSize-1)) / pageSize;

    public void firstPage() {
        pageNumber = 1;

    public void previousPage() {
        pageNumber = Math.max(1, pageNumber - 1);

    public void nextPage() {
        pageNumber = Math.min(maxPage, pageNumber + 1);
    public void lastPage() {
        pageNumber = maxPage;

    public void loadPage() {
        Id[] currentPage = new Id[0];
        records = new Account[0];
        for(Integer index = (pageNumber-1)*pageSize, 
                size = Math.min(pageNumber*pageSize, recordIds.size());
                index < size; index++) {
        Map<Id, Account> accounts = new Map<Id, Account>(
            [SELECT Name, Industry FROM Account WHERE Id = :currentPage]
        for(Id recordId: currentPage) {

    public void changePageSize() {
        maxPage = (recordIds.size()+(pageSize-1)) / pageSize;

    public void refreshView() {

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.