Monday 11 December 2017

Batch Apex - Detect failed record Id's in Execute() method

Email notification of failed records from Execute /  Finish methods ?

We can send from any of the method.But ideal way is to send from Finish method.

Why its recommended to send notifications from Finish method ?

This finish method called after all batches are processed,It means only one time execution for complete job.

What is the use of  Database.Stateful ?
Batch Apex is by default Stateless.
To maintain the state across all transactions we can implement this interface 'Database.Stateful'.
Ex:
Capturing the failed record information in Execute method between all transactions and assigning to member. And use that member in Finish method.

Note : Only instance member variable retain their values between transaction.

Ex: Static member ,Which will not retain value between transaction.

The final o/p doesn't have any values captured.For the static member.



Sample code to find the failed records of Batch Apex  & Used Member variable to maintain the state


3 comments:

  1. Very Helpful.

    ReplyDelete
  2. Very Helpful.. beautifully explained this blog clear my all doubts.. related to batch class

    ReplyDelete
  3. can you please add DT_UTILITY class

    ReplyDelete