I am new to Salesforce and looking for a solution.

I am writing a Job, which reads lead records more than 1000 using the query and process them in chunks for every 100 and updates them. In the finish, i am sending a email with the status of the job and I also need to know, how many are total records processed by reading the query and how many are updated in each chunk batch apex.

Is there a way to declare the global variable and pass it through all the batch chunk processes and at the end in the finish method it will show us the result.

Appreciate any help!!


Yeah, your batch class needs to also implement Database.Stateful and then you can have instance variables that don't lose state between batches.

  • @Vid please be sure to mark this answer as correct as well. Thanks. ;-) – Andrew Fawcett Aug 7 '13 at 7:50

You have to implement Database.Stateful in your batch class. This instructs Force.com to preserve the values of your static and instance variables between transactions.

  • 1
    Hi Nitish, links for reference are ok but relevant content should be included here directly, links tend to break over time. SFSE isn't the best place to try and drive traffic to a blog :) – Matt Lacey Dec 22 '16 at 2:09
  • 1
    @Nitish - How does this add to the already accepted answer? – Eric Dec 22 '16 at 2:36
  • 1
    @Eric The main addition seems to have been an attempt to drive traffic to an outside blog (you can see from the edit history). – Adrian Larson Dec 22 '16 at 2:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.