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
Samir Mahtani 4Samir Mahtani 4 

Apex Issue/ " Failed to process batch"

We are getting continuous issues via email with the following message: 

Apex script unhandled exception by user/organization: 00538000006N5EX/00D50000000JW2O 

Failed to process batch for class 'c_component_allocation_bulk_sync' for job id '7071T00008jxauJ' 

caused by: System.LimitException: Too many query rows: 50001 

Class.c_component_allocation_change_container.priors: line 380, column 1 
Class.c_component_allocation_change_container.positive_priors: line 334, column 1 
Class.c_component_allocation_change_container.manage_updates: line 202, column 1 
Class.c_component_allocation_change_container.process_state_change: line 100, column 1 
Class.c_component_allocation_change_container.update_states: line 79, column 1 
Class.c_component_allocation_change_container.<init>: line 66, column 1 
Trigger.c_component_allocation_mod: line 13, column 1 

Does anyone know what the issue might be? We are seeing issues with Chargify which is an integrated software. 
VinayVinay (Salesforce Developers) 
Hi Samir,

There is a limit to the number of records that that can be retrieved  by the SOQL Query which is 50000 records. Attempting to query the records having the number more than this will give the error which you are getting.To query the records more than its limit, you need to use a Batch Class which provides a fresh limit of 50k records by resetting the limits.

References for more details:
https://salesforce.stackexchange.com/questions/28228/system-limitexception-too-many-query-rows-50001
https://salesforce.stackexchange.com/questions/105609/system-limitexception-too-many-query-rows-50001-even-though-soql-has-limit-10

Hope this helps..

Thanks
AnudeepAnudeep (Salesforce Developers) 
You are running into Too many query rows governor limit. The exception is being thrown because the maximum number of rows you can return in SOQL calls in Apex is 50000. I recommend troubleshooting this based on the Apex Class name and Methods in the description

I recommend checking the debug logs. From the logs, see how many rows the SOQL query returns and run the same query through the workbench and verify if the query has a where clause and limit  

For the sake of debugging note that you can check how many query rows have been used via Limits.getQueryRows();.