Collection size exceeds maximum size of 1000 error in Salesforce means List, Set & Map size exceeded more than 1000 to be shown on the Visualforce page.
To avoid this, use wrapper class and get set of first 1000 records, save it and then retrieve the next and so on.
Sample code:
Visualforce page:
<apex:page controller="thousandLimit">
<apex:pageBlock >
<apex:repeat value="{!thousandBlocks}" var="block">
<apex:pageBlockTable value="{!block.cases}" var="c">
<apex:column value="{!c.CaseNumber}"/>
<apex:column value="{!c.owner.name}"/>
<apex:column value="{!c.App_Process__c}"/>
<apex:column value="{!c.Load__c}"/>
<apex:column value="{!c.subject}"/>
<apex:column value="{!c.Estimated_Completion_Date__c}"/>
<apex:column value="{!c.Complete__c}"/>
<apex:column value="{!c.Priority}"/>
<apex:column value="{!c.Case_Age_Days__c}"/>
</apex:pageBlockTable>
</apex:repeat>
</apex:pageBlock>
</apex:page>
Apex Controller:
public class thousandLimit
{
private limitWrapper[] thousandBlocks = new limitWrapper[]{};
private final integer listLimit;
public thousandLimit()
{
listLimit = 1000;
}
public limitWrapper[] getthousandBlocks()
{
thousandBlocks = new limitWrapper[]{};
integer counter = 0;
integer loopCount = 0;
case[] tmpcase = new case[]{};
for( Case c : [ SELECT CaseNumber, owner.name, App_Process__c, Load__c, subject, Estimated_Completion_Date__c, Complete__c, Priority, Case_Age_Days__c
FROM Case
WHERE (Status != 'Closed' or Status != 'Declined') and Estimated_Completion_Date__c = null and owner.Alias like 'EA%' order by owner.name]
)
{
if(counter < listLimit)
{
tmpcase.add(c);
counter++;
}
else
{
loopCount++;
thousandBlocks.add(new limitWrapper(tmpcase,loopCount));
tmpcase = new case[]{};
tmpcase.add(c);
counter = 0;
}
}
if(thousandBlocks.size() == 0)
{
loopCount++;
thousandBlocks.add(new limitWrapper(tmpcase,loopCount));
}
return thousandBlocks;
}
public class limitWrapper
{
public case [] cases {get;set;}
public integer blockNumber {get;set;}
public limitWrapper(case[] accs, integer i)
{
cases = accs;
blockNumber = i;
}
}
}
Thank you so much for sharing this.. This is a time saver. Happy coding!
Its good one. Thanks for sharing it.
Thanks very much for posting this. I noticed one thing that I think is missing. The only time tmp is added to thousandblocks is when it reaches the limit which results in the final tmp list not being added. So if there were 1020 then the last 20 would not get added.
So right before the return thousandBlocks; statement I added the line
thousandBlocks.add(new limitWrapper(tmpcase,loopCount));
This solution saved me today! Thanks a lot! 🙂
Thanks a lot!!!!
thanks
I came across this issue and choose your solution and implemented it. Only one issue i found that after 1000 record, i can see the header again. How can i get rid of the header ? Please let me know on this?
The problem should be with the list of wrapper you are developing. Make sure you are getting the cases from the wrapper and displaying it.