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
Nitin ParandeNitin Parande 

APEX BATCH JOB - Abruptly ending without errors but showing ALL Batches completed.

I have strange behavior with a APEX Batch job

I run this job with batch size of 1 and it puts a job of 1000 Batches to process. However after it run for some time I have seen following behavior

1. I see the batches are processing fine say like it has processed 300. All of a sudden I see all jobs completed and it says it processed 800 batches (not sure where the other 200 batches go). Looking at the data looks like it did not process everything that should have been processed.

2. Some times I see it is processing fine say at 400th batch and all of a sudden it would say completed with all 1000 batch completed. Looking at the data looks like it did not process everything that should have been processed.

Any ideas why this could happen ?

The batch class internally call another class method in the execute method. This method has some what more logic in it. However this method when run individually does not have any issues (No Heap size issue or other performance issues).  Not sure because of the call method the complete Batch job is abruptly aborted. (with specifying any error)

I have opened a case with Salesforce but want to see if any one else have seen this issue.   
 
Sudipta DebSudipta Deb
Hi Nitin,

Sounds interesting. What about your test class? Seems like some issue with bulkification of the code? I would suggest you the below stuffs while you are waiting for Salesforce Support's reply -
  • Write some test methods to test bulkification of your code? Try to simulate the same scenarios with test class
  • Put Exception Logic and System.Debug to see if you are getting any Debug Logs there.
Meanwhile if you can post your code here, I can have a look.
Nitin ParandeNitin Parande
@Sudipta,

Here is some additional backround to analyse - 

CLASS A Method   (has some heavy business logic).  This was earlier triggered from external system using REST APEX Call.  Every night 1000  calls were being made to this Class A Methos "in sequence"  without any issues from external system.

I  basically now want to call this CLASS A Method through APEX Batch process in Salesforce.  (with Batch size 1). So 1000 batches in one APEX Batch job.

Class A  has over 4000 lines of code of which I think around 20% or so lines will be executing based on the data scenario. This Class A runs fine when called through REST Call from external system.

Only difference now is external system was calling this CLASS A Method in sequence whereas I am now batching this in Salsforce in  one APEX job of 1000 batch which "may" be running in parallel.  A Batch will get it's  own governor limit so was expecting no issues even if multiple batches are running in parallel.   (My Assumption is salesforce batching is managing the resources so should handle throtlling of these 1000's batches efficiently to process correctly.)  Strange thing is there are no errors nor any aborting of any jobs.

  
Sudipta DebSudipta Deb
Hi Nitin,

Batch Apex are stateless by default. But you can make the Batch Apex class itself stateful by implementing the Stateful interface. This instructs Force.com to preserve the values of your static and instance variables between transactions.

global class YOURBATCHCLASS implements Database.Batchable<sObject>, Database.Stateful{

}

Another approach is to send a mail to yourself to check number of record passed and failed. Create one counter and share/ use in each execute method use same. Test this in your sandbox and may be it will give you some insights.

Please accept my solution as Best Answer if my reply is helpful.
Nitin ParandeNitin Parande
@Sudipta,

Yes, I have email logic to email  any exception  caught in the execute method. No emails. Will reconcile the batches executed to actual work done and see.
 
Nitin ParandeNitin Parande
Analysing Data and Logs following is my observation - 

for the APEX JOB 
total batches  submitted 1000
total batches processed 1000
total failures 0

finish method executed succesfully
No errors in any batch (as idenfied through failure counters in execute method and displayed in the finish method)
Actual batches successfully processed 612 (as identified through data updated in backend tables)

382 batches lost in cyberspace.
Angello Camacho DragoAngello Camacho Drago
I am facing the same problem, apparently is a problem of Summer '17, can you report the issue here:

https://success.salesforce.com/issues_view?id=a1p3A000000esVNQAY
ram chowdary 11ram chowdary 11
Hey @Nitin Parande what was the response from Salesforce on your issue.