4

When I look at the "Monitor Bulk Data Load Jobs" link in my salesforce org, I see a count of batches consumed in the last 24 hours. An example is shown below.

Your organization has processed **821 batches** in the last 24 hours. Your organization can process 2,000 batches in a 24-hour period.

Is there a way to get this information by running a SOQL?

1
  • the object to query (if it were queryable -- not possible as of Winter 18) is AsyncApiJob
    – cropredy
    Commented Dec 14, 2017 at 21:20

3 Answers 3

2

From this it doesn't seem like there's a way to query for Bulk Load jobs.

You can query the AsyncApexJob table for a count of records where the type is BatchApex, which is the only seemingly log of all things Batch

Select count(Id) from asyncapexjob where JobType='BatchApex' and CreatedDate > Yesterday

However this doesn't seem to include Bulk Data Loads

2

The snippet of code below gets the number of batches, and also the number of items in all batches:

List<AsyncApexJob> lstjobs=[
    SELECT
        Id,
        TotalJobItems
    FROM
        AsyncApexJob
    WHERE
        CompletedDate = TODAY
        AND JobType='BatchApex'];

Integer jobItemsCount = 0;
Integer batchesCount = 0;
for(AsyncApexJob async : lstjobs) {
    jobItemsCount += async.TotalJobItems; //Add the no of batches processed
    batchesCount++;
}
1
  • I tried it and it doesn't seem to work because of two reasons. 1) This doesn't seem to include bulk data loads as techtrekker mentioned in the below note. 2) CompletedDate = TODAY is not the correct where clause. It has to be a running 24 hour window. So, I tried CompletedDate >= System.now().addseconds(-86400) in a apex job and still the result was wrong because of #1. Commented Dec 3, 2012 at 15:04
0

You might have to use HTTP requests to get that info. See Bulk API for more info, this link looks particularly interesting.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .