You need to sign in to do that
Don't have an account?

Batch Apex Error Handling
Trying to figure out how I can prevent roll-back on Apex Batches for a Scheduled Class and then capture the id's and messages for the records that fail in an update call and email that out to an admin. Documentation doesn't seem clear on this.
This needs to work in a scheduled (Batch) apex class. So we're not talking about doing a single record update here. Here is the code exerpt I have from my execute class:
The Apex logs are showing the error happening but I need to be able to capture all id's that are failing and email those out.
ok ... got it figured out, although I'm wondering if there is a way to capture this without having to save the errors into an object for passing back into the finish class for the batch. Here's the snippet now:
Then in the finish class I retrieve the errorlogs records to post into an email message for sending.
I know this is a few weeks old now but I had the same problem and this helped me with part of the solution but I also have a solution for the point about capturing the error messages:
You can keep a global string containing all of the messages as they build up. To make sure that the content of the string persists accross multiple batches you implement "Database.stateful" which is simply a case of adding it to your class definition for the batch process e.g.
it is automatically handeled by Salesforce that if any batch meets exception then that record will be rolled back of that batch.