Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.
for(PricebookEntry pbe:[Select product2Id from PricebookEntry where PriceBook2Id = :pbId]){
            productIds.add(pbe.product2Id);
        }

I am getting the following exception.

System.LimitException: Too many query rows: 50001 An unexpected error has occurred. Your solution provider has been notified. (Database).

It should process the records in batch why am i getting the above error?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Even if you are executing in batch please note that the execute class still holds all the governor limits .Only the Object which is queried in Database.QueryLocator gets chunked while processing .The query in constructor or the start method or your scope is prevented from query limit .If you have 50000 pricebook entry for PriceBook then query will fail.

share|improve this answer
    
I want to query all the products from a pricebook and show it on VF page with pagination.Can you tell me any better way to query this. –  NeverGiveUp Dec 27 '12 at 8:54
    
Vipul try using standard set controller using database.query locator .This will have pagination feature. salesforce.com/us/developer/docs/pages/Content/… –  Mohith Shrivastava Dec 27 '12 at 8:59
    
con = new apexPages.StandardSetController(Database.getQueryLocator([select Id , Name Product2 where Name like :('%'+SearchKeyword+'%')]); I am using the above query but I want to query the Products based on pricebook I have more than 50000 records. –  NeverGiveUp Dec 27 '12 at 9:38
    
Vipul A maximum of 50 million records can be returned in the Database.QueryLocator object. If more than 50 million records are returned, the batch job is immediately terminated and marked as Failed.So i would suggest set pagesize and limit to 1000 records on a page –  Mohith Shrivastava Dec 27 '12 at 9:44
    
You can use filters also for your query –  Mohith Shrivastava Dec 27 '12 at 9:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.