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
prasanth kumarprasanth kumar 

not displaying 2000 records in visualforce page.

i am getting this error. 
User-added image

 
<apex:page controller="postalcode" readOnly="true">
    <apex:pageblock>
<apex:variable value="{!1}" var="rowNum"/>
        
    <apex:repeat value="{!post}" var="a"  >
       <apex:outputText value="{!FLOOR(rowNum)}"/>...... <apex:outputtext value="{!a.Postal_code__c}" /><br/>
                <apex:variable var="rowNum" value="{!rowNum + 1}"/>
        </apex:repeat>                                      
    
    </apex:pageblock>
    	
</apex:page>











public class postalcode {
    
    public list<Postal_codes__c> post{set;get;}

    public postalcode()
    {
        post=[select id,Postal_code__c from Postal_codes__c limit 2000];
    }
}

 
James LoghryJames Loghry
Although you can have a much larger collection of records in Apex (in Apex the limitation is on the heap size of your class), but with the apex:repeat tag you can only iterate over 1000 records as the error mentions.

To overcome this, you can use nested repeats with a wrapper class.  I provided an example below, but haven't tested whether or not it compiles or works correctly, so that's up to you.
 
<apex:page controller="postalcode" readOnly="true">
    <apex:pageblock>
        <apex:variable value="{!1}" var="rowNum"/>
        
        <apex:repeat value="{!wrappers}" var="w"  >
            <apex:repeat value="{!w.pcs}" var="a">
                <apex:outputText value="{!FLOOR(rowNum)}"/>...... <apex:outputtext value="{!a.Postal_code__c}" /><br/>
                <apex:variable var="rowNum" value="{!rowNum + 1}"/>
            </apex:repeat>                                      
        </apex:repeat>
    </apex:pageblock>
</apex:page>











public class postalcode {
    
    public list<pcwrapper> wrappers{private set;get;}

    public postalcode()
    {
        List<pcwrapper> wrappers = new List<pcwrapper>();
        pcwrapper wrapper = null;
        for(Postal_Codes__c pc : [select id,Postal_code__c from Postal_codes__c limit 2000]{
            if(Math.mod(wrappers.size(),1000) == 0){
                wrapper = new pcwrapper();
                wrapper.pcs = new List<Postal_Codes__c>();
                wrappers.add(wrapper);
            }
            wrapper.pcs.add(pc)
        }
    }

    public class pcwrapper{
        publi List<Postal_Codes__c> pcs {get;set;}
    }
}

 
Atul GuptaAtul Gupta
prasanth, I just tried the same code in my developer org on case object. I seems to work fine.

It there something, that you might be missing out in this question.
James LoghryJames Loghry
Atul, your example is probably working because you likely don't have over 1000 case records in your developer org
Atul GuptaAtul Gupta
James, I have more than 2000 Case records in my org. See the screenshot below

User-added image

As for the apex:repeat tag, as per documentation (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_readonly_context_pagelevel.htm)
 
In addition to querying many more rows, the readOnly attribute also increases the maximum number of items in a collection that can be iterated over using components such as <apex:dataTable>, <apex:dataList>, and <apex:repeat>. This limit increased from 1,000 items to 10,000.

Now even I am confused why Prasanth's code is not working.