[SalesForce] Collection size 1,768 exceeds maximum size of 1,000.

I have two VF pages one to display a list of records on screen and other to export the list as csv file.

For the the page where i am displaying on the screen, i am using standard set controller and displaying data within a apex:repeat. which works great.

When i try to export to csv and call the VF page. it throws out the error

Collection size 1,768 exceeds maximum size of 1,000.

I have the Vf page for the export using readonly="true"

As per the documentation the

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 ,
, and . This limit increased from 1,000
items to 10,000.

VF page Code

<apex:page controller="CVFC_MasterOrder" contentType="application/vnd.ms-excel#{!filename}" cache="true" readOnly="true">
    <table>
        <thead>
        <tr>
            <apex:repeat value="{!FieldsExp}" var="f"> 
                <th>{!f.Label}</th>
            </apex:repeat>
        </tr>
        </thead>
        <tbody>

            <apex:repeat value="{!MasterListExp}" var="m"> 
            <tr>
                <apex:repeat value="{!FieldsExp}" var="f"> 
                   <apex:outputPanel id="rec" rendered="{! If(f.Type == 'textarea' ,true,false) }">

                        <td>{!m[f]} </td>
                    </apex:outputPanel> 
                    <apex:outputPanel id="rec2" rendered="{! If(f.Type == 'date' ,true,false) }">

                        <td>
                            <apex:outputText value="{0,date,short}">
                                <apex:param value="{!m[f]}" /> 
                            </apex:outputText> 

                        </td>
                    </apex:outputPanel> 
                    <apex:outputPanel id="rec5" rendered="{! If(f.Type == 'boolean' ,true,false )}">
                        <apex:outputPanel id="rec3" rendered="{! If(m[f] == true ,true,false ) }" >
                            <td>Yes </td>
                        </apex:outputPanel>
                        <apex:outputPanel id="rec4" rendered="{! If(m[f] == false ,true,false ) }" >
                            <td>No</td>
                        </apex:outputPanel>
                    </apex:outputPanel>
                    <apex:outputPanel id="rec1" rendered="{! If(f.Type != 'textarea' && f.Type != 'boolean' && f.Type != 'date',true,false) }">
                        <td><apex:outputfield value="{!m[f]}" /></td> 
                    </apex:outputPanel> 
                </apex:repeat>
            </tr>
            </apex:repeat>

        </tbody>
    </table>     

</apex:page>

Apex class Method

public pageReference exporttoxls()
 { 
     String query = CUtilityFunctions.generateQueryFromFieldSet('Master_Order__c','MasterOrderQuery',null,wherecondition);  
                query+= ' LIMIT 50000 ';
                System.debug('Query ' + query);
        MasterListExp =  database.query(query); 
        filename ='Masterorder'+ Datetime.now().format('yyMMddHHmmss') + '.xls';
   return new pageReference('/apex/exporttocsv');
 }

Any workarounds to get rid of this error.

Best Answer

A simple solution - instead of list, use map collection type.

This works check this post Why can Visualforce iterate over >1000 item collection if it's a map?