+ Start a Discussion
kprkpr 

Selecting more than 1000 rows in a controller and displaying in a visualforce page

Hi,

 

I am new to visualforce development. I am having an issue with fetching more than 1000 records from database to be displayed on a visualforce page.

 

I am getting the exception 'System.Exception: collection exceeds maximum size: 1001'

 

Can anyone help me?

Here is the code snippet:

 

public void getProductLists(){
//Each iteration of the outer for loop fetches 1000 records....There are about 10K records in total
for(List<PricebookEntry> allProducts : [Select p.Product2Id,p.Product2.Name,p.Product2.Description,p.Product2.Family From PricebookEntry p where p.Pricebook2Id =: chObj.PriceBook_Id__c])
{

for(PricebookEntry p:allProductsList){
if(recommendedProductMap.containsKey(p.Product2Id) ){
recommendedProductsList.add(new sProduct(p));
}
else{
//Now after filtering, this list should contain some 5K+ records.But I get the exception 'System.Exception: collection exceeds maximum size: 1001'
allOtherProductsList.add(new sProduct(p));

}

}

}

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
DManelskiDManelski

You'll need to use a StandardSetController to grab more than 1,000 records (although I believe that 10K is the limit for set controllers).  What you're running into is the hard limit of list size. Here is the link to Apex documentation on the subject:

 

 http://bit.ly/vd5R0

All Answers

DManelskiDManelski

You'll need to use a StandardSetController to grab more than 1,000 records (although I believe that 10K is the limit for set controllers).  What you're running into is the hard limit of list size. Here is the link to Apex documentation on the subject:

 

 http://bit.ly/vd5R0

This was selected as the best answer
kprkpr
Thanks for the reply!It helped me solve my problem.