How to get complete list of records in List view

How do i get the complete list of records in a list view. I know using getRecords() we can get but its only limited to maximum of 20 records. But i need list of complete records for the List view. Is it possible?.

ApexPages.StandardSetController setCon;
        List<Bug__c> lChanges = new List<Bug__c>();
        public GenerateCardListView_Cntrl(ApexPages.StandardSetController controller) {
            setCon = controller;
            lChanges = setCon.getRecords();            
            system.debug('&&&&&'+setCon.getRecords());
            system.debug('&&&&&'+setCon.getRecords().size());
        }

The size in the debug returns 20 if the size is more than 20.

Answer

The StandardSetController works a bit like a database cursor, you need to ask for records a page at a time. The key methods are getHasNext() and next(). Using these around each call to the getRecords() method until you’ve moved through the entire record set. This simple controller demonstrates this…

public with sharing class DemoStandardSetController 
{
    public List<Test__c> AllRecords {get;set;}

    public DemoStandardSetController(ApexPages.StandardSetController stdSetController)
    {
        stdSetController.addFields(new List<String> { 'Name' });

        AllRecords = new List<Test__c>();

        while(stdSetController.getHasNext())
        {
            for(Test__c testRecord : (List<Test__c>) stdSetController.getRecords())
            {
                AllRecords.add(testRecord);
            }
            stdSetController.next();
        }
    }
}

My demo page looks like this…

<apex:page standardController="Test__c" extensions="DemoStandardSetController" recordSetVar="fred">
    <apex:pageBlock >
        <apex:pageBlockTable value="{!AllRecords}" var="Record">
            <apex:column value="{!Record.Name}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

enter image description here

Attribution
Source : Link , Question Author : Anil Shivaraj , Answer Author : Andrew Fawcett

Leave a Comment