We wrote a batch class on a custom object "Staging_Product__c". In the batch, in the start method we are getting records as below
global Database.Querylocator start(Database.Batchablecontext BC){
String query = 'Select Id,Name FROM Staging_Product__c WHERE Status__c=\'Pending\'';
Database.QueryLocator ql = Database.getQueryLocator(query);
List<Staging_Product__c> mptlist = (List<Staging_Product__c>) database.query(query);
for (Staging_Product__c mpt : mptlist) {
mpt.Status__c = 'In Progress';
}
update mptlist;
return ql;
}
We are updating the same records which are going to be processed by the batch job to In Progress so that if the second batch job based on same batch class started in parallel with first batch job doesn't pick the records which have already been picked up by the first batch job.
Does this approach okey? Does query locator keeps a local copy of queried records?
Please let me know your thoughts