0

Basically the querylocator returns about 200000 records at the start, I can see it in logs, also there are not any errors or limits warnings. The size of each job matters because the smaller it is,more records are processed. In particular passing from 2000 to 200 unexpectedly works better. How can be this possible? I searched in questions like this a clearer answer but every solution seems to work for that case only. Another tip, if I launch my job on a handful number of records it works perfectly. As stated in the title my main query is very very simple like:

SELECT id,name... FROM MycustomObject where Attribute_1 = :'something'

So, apart from the solution I wish I could know how is this possible, and how to fix it permanently so that I have not to check every day if my batch is executed perfectly.

0

1 Answer 1

0

I have a strong suspicion that your batch is running into a limit exception. And as limit exception kills the whole transaction. One would not be able to save logs after it.

Fortunately, for the same reason, we have in Winter 19, an ability to fire an event when something wrong happens in batch.

public with sharing class YourSampleBatchJob implements Database.Batchable<SObject>, 
   Database.RaisesPlatformEvents{ 
   // class implementation 
} 

You just have to add an extra interface to your batch, Database.RaisesPlatformEvents.

If batch goes in any limit exception(Read any exception), it will fire event of type BatchApexErrorEvent.

That event can be subscribed by APex Triggers, Process Builder, or even Lightning:empAPI which will give you an ability to see what went wrong.

Src: https://releasenotes.docs.salesforce.com/en-us/winter19/release-notes/rn_apex_platformEvents_from_batchApex.htm

Src: https://twitter.com/fishofprey/status/1027392824134721536?lang=en

You must log in to answer this question.

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