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
Rajesh Reddy 29Rajesh Reddy 29 

How to use Database.Stateful in batch Apex?

Hi All,
In my org I have 1L Accounts in account I have custom field account__c every day I need to display total amount for all account when my batch job runs (For exam  I am working in banking domino every day amount (amount__c) is updating when my batch job runs for all accounts .
Thanks In Advance 
Regards,
Rajesh
 
Best Answer chosen by Rajesh Reddy 29
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Rajesh Reddy,

Batch Apex is stateless by default. That means for each execution of your execute method, you receive a fresh copy of your object. All fields of the class are initialized, static and instance. If your batch process needs information that is shared across transactions, one approach is to 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.

Please refer the below link for reference 
Please mark it as best answer if the information is informative/

Best Regards
Rahul Kumar