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
raSFUserraSFUser 

Using Scope Database.executeBatch()

I have a question about using batch and the passing in a Scope, lets say im processing a batch of 53 records, however due to other governance limits i need to use scope to limit 30 records per transaction.

e.g. 

Integer scopeSize = 30; jobId = Database.executeBatch(batch, scopeSize);

If I use the something like the above, will one or two entries be created in the Queue ?
 

Select Count(Id) FROM AsyncApexJob Where Status = 'Holding'

Everything I have read doesn’t seem to detail this bit….

ShirishaShirisha (Salesforce Developers) 
Hi,

Greetings!

Yes,if you use the scopeSize as 30 and you are trying to process the 50 records then the records will be processed in 2 batches as the ScopeSize will be the number of the records per batch.

However,you can only see one job on the UI with the number of records processed.

Please mark it as best answer if it helps you to fix the issue.

Thank you!

Regards,
Shirisha Pathuri
Malika Pathak 9Malika Pathak 9
Hi,
 
Integer scopeSize = 30; jobId = Database.executeBatch(batch, scopeSize);
Yes, if you pass scopeSize of 30, the records will auto processed in two batches as records are greater than scopeSize.
and
Select Count(Id) FROM AsyncApexJob Where Status = 'Holding'
It is used to Count the flex Queue Size:
List<AsyncApexJob> jobs = [SELECT 
    Id,
    CreatedDate,
    CreatedById,
    JobType,
    ApexClassId,
    Status,
    JobItemsProcessed,
    TotalJobItems,
    NumberOfErrors,
    CompletedDate,
    MethodName,
    ExtendedStatus,
    ParentJobId,
    LastProcessed,
    LastProcessedOffset
 FROM AsyncApexJob
where ApexClass.name= 'bacth class name'
and Status = 'Holding'];
for(AsyncApexJob job : jobs){
    System.debug('stop job : ' + job.id + ', ApexClassId= ' + job.ApexClassId);
    System.abortJob(job.id);
}


If you find this helpful, please mark it as the best answer to help others.