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
Nitin SehgalNitin Sehgal 

Creating a wrapper class in batch apex

Hi everyone,

 

I have created a wrapper class in batch apex and created a list of that class. I did some calculation in execute method and store some data but i am not able to get that data in finish method. My wrapper class is public and List<wrapper class> is private.

 

Can anybody help me? 

Best Answer chosen by Admin (Salesforce Developers) 
Sean TanSean Tan

So from what I'm understanding you're building a list of your custom wrapper class in your execute method, and maintaining that list at the class instance level. You then want to use said list in the finish method.

 

If so try using the Database.stateful interface in your Batch APEX class:

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm

 

See: Database.Stateful

 

Be careful though, since maintaining these objects adds to your total heap size usage

All Answers

Sean TanSean Tan

So from what I'm understanding you're building a list of your custom wrapper class in your execute method, and maintaining that list at the class instance level. You then want to use said list in the finish method.

 

If so try using the Database.stateful interface in your Batch APEX class:

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm

 

See: Database.Stateful

 

Be careful though, since maintaining these objects adds to your total heap size usage

This was selected as the best answer
Nitin SehgalNitin Sehgal

Hi Sean Tan,

 

Thanks a lot for your solution. It worked for me.