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
Divs@newbieDivs@newbie 

Collection limit exceeded when trying to export vf page to csv

Hello Experts,

We have developed a VF page, where we have export functionality that redirects to another vf page and downloads the file in .csv format. However, the data is more 1000 and I am using apex:repeat in the export vf page and I run into the collection limit exceeded error message.

I have gone through many posts in the forum, where experts suggest to use nested lists or nested repeats and also making the VF page readOnly but none of them worked for me.

Could you please let me know if there is a way to download the csv file for more than 1000 records either by any javascript function or apex:repeat/ apex:dataTable/ apex:pageBlockTable . As this is a key feature that our clients are expecting so would like to know if this could be possible in any way.

Greatly appriciate your assitance here.

Thanks
Best Answer chosen by Divs@newbie
AnudeepAnudeep (Salesforce Developers) 

There is one simple trick to bypass the collection size limit on-page. 
Instead of using a list of objects just use any map like Map<Id,SObject> and your page will never show this error again. See this post to learn more

The limit which you are hitting is a hard limit. In other words, it is an implementation restriction. The implementation restrictions are in place to ensure that any piece of code does not degrade the performance of your org.

These limits cannot be increased and to overcome the issue, you must modify your code based on the suggestions below:

1. Splitting up the list in your class into small sublists and process the sublists. This workaround is described in more detail in this thread

2. Limit the size of the files uploaded by the user to 1000 lines.

When you upload a large amount of data into Salesforce, a suggestion would be to make use of API instead. You can have a trigger in Salesforce to process the incoming data and attach the incoming contact records to the desired campaigns. Moreover, if you use Bulk API other than standard API, you can process 10,000 records in a single API call without hitting any limits. For example, if you make merely 10 API calls, you will be able to process 100,000 records on the fly.

In that case, too, you will need to make sure that your trigger is bulkified. In other words, it is written to handle data in bulk. You can use Data Loader in order to upload csv's directly into Salesforce.

Anudeep

All Answers

AnudeepAnudeep (Salesforce Developers) 

There is one simple trick to bypass the collection size limit on-page. 
Instead of using a list of objects just use any map like Map<Id,SObject> and your page will never show this error again. See this post to learn more

The limit which you are hitting is a hard limit. In other words, it is an implementation restriction. The implementation restrictions are in place to ensure that any piece of code does not degrade the performance of your org.

These limits cannot be increased and to overcome the issue, you must modify your code based on the suggestions below:

1. Splitting up the list in your class into small sublists and process the sublists. This workaround is described in more detail in this thread

2. Limit the size of the files uploaded by the user to 1000 lines.

When you upload a large amount of data into Salesforce, a suggestion would be to make use of API instead. You can have a trigger in Salesforce to process the incoming data and attach the incoming contact records to the desired campaigns. Moreover, if you use Bulk API other than standard API, you can process 10,000 records in a single API call without hitting any limits. For example, if you make merely 10 API calls, you will be able to process 100,000 records on the fly.

In that case, too, you will need to make sure that your trigger is bulkified. In other words, it is written to handle data in bulk. You can use Data Loader in order to upload csv's directly into Salesforce.

Anudeep
This was selected as the best answer
Divs@newbieDivs@newbie
Thank you! Using Map helped to resolve the issue.