2

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.

3

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?

3
  • 1
    Thats interesting...I will certainly check this out :) As per documentation the list should allow holding 10000 if the VF page is readonly right – Prady Jun 18 '18 at 7:51
  • yes @Prady if readonly then it will iterate over 10K. I saw already in your code that's why i gave this solution. – Ratan Paul Jun 18 '18 at 8:15
  • @Prady is this issue resolved? – Ratan Paul Jun 23 '18 at 11:55
0

You can create List of List which could hold up to 10,000 records (max).

Here is an example from my blog Visualforce with JQuery Datatable for sorting, pagination and handling 10000 records

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.