You need to sign in to do that
Don't have an account?
Governor limit hit in the Batch job
Hi,
Can anyone give the solution for the following issue:
I created a custom object called xyz__c, which has more than 50k + records. I'd like to process all these records in the Batch job. This code in inside the start(....) method and the return type is List<SObject>.
Note: I found some issues with the QueryLocator and so I'm using List<SObject> as a return type.
Error: 19:5:19.106|EXCEPTION_THROWN|[86,38]|System.Exception: Too many query rows: 10001
Source code:
List<SObject> rList=new List<SObject>();
for( List<SObject> rr:[SELECT Id,Name,OwnerId,RecordTypeId,RecordType.Name,Account__c,WebID__c,WebID__r.Status__c,
Type__c,Review_Frequency__c,
Month__c,Due_Date__c,Stop_Clone_Date__c,Status__c,Recommendations__c,Recommendation_Status__c,
ProCare_Health__c,DAP_Health__c,
Submitted_Directories__c,Site_Check_Status__c,Previous_MM_Record__c, Previous_MM_Record__r.Id
FROM xyz__c
WHERE (CALENDAR_MONTH(Month__c) = :this.cloningMonth AND
CALENDAR_YEAR(Month__c) = :this.cloningYear AND
Stop_Clone_Date__c = NULL AND
Review_Frequency__c = :this.reviewFrequency AND
WebID__r.Status__c = :this.webIDStatus AND
UniqueID__c NOT IN :previousMMrecordList)
ORDER BY Id ]){
rList.addAll(rr);
}
you have to set batch size as 1 or 2, depends upon your queries size
Looks like your SOQL query is returning more the 10,000 rows - which is not surprising since as you said, you want to process upto 50K records using Batch Apex.
The problem is that if you return a List from the start method of a Batch Apex class, you're still subject to the 10,000 governor limit that applies to all SOQL queries. In other words you can only process upto 10,000 records if you return a List.
Return a QueryLocator instead - that way you won't be subject to the 10,000 limit and you can return and process upto 50 millions rows in your Batch job.
Hope this helps.
Thanks for the details.
But I found a limitation with QueryLocator. I can't able to pass a List as a query parameter. So I',m using List as a return type.
Ex:
class xyz{
public List<String> rSet {set;get;}
private String query;
QueryLocator start(BatchableContext BC){
query='Select Id,Name from abc__c where Id NOT IN ' + rSet ; - I'm getting the error over here. As the passing parameter is a List data type and the size of the List is around 50K. So I couldn't even convert a List to a String, where the String size is exceeding.
return QueryLocator.getQuery(query);
}}
Ok - so it looks like you need to make a SOQL query that excludes a certain set of records. You need to define a variable of local scope in order to do that. Try this: