0

I have a batch job which gets a number of users in the start interface.

So I implement the following APIs

global Database.QueryLocator start(Database.BatchableContext bc) 
global void execute(Database.BatchableContext bc, List<User> users) 
global void finish(Database.BatchableContext bc) 

I am wondering is there anyway I can get a handle to all users (not a batch of users) in the finish method?

Note: I was hoping to do this and keep my class stateless.

Thanks.

2 Answers 2

2

You would need to implement the Stateful interface and for every iteration of your execute method, you would need to add the users to a member level users list, e.g.

allUsers.addAll( users );

And then reference this in your finish method.

However, be wary of the maximum heap size (15mb I think), although, I guess you'd have to be querying a lot of users with a lot of data to exceed it.

If you don't want to maintain state using the Stateful interface, you would have to store the users in a custom object. You could serialise them to a text file attachment or some other method of self rolled state.

2
  • Hawthon. I try to avoid state everywhere. But thanks for suggestions. I will update question to be clearer.
    – dublintech
    Commented Jan 10, 2013 at 15:54
  • 1
    @dublintech, ok i edited with another suggestion if you don't want to use Stateful Commented Jan 10, 2013 at 15:57
2

If you want to keep it stateless still you can query all the Users in finish method provided the context limits dont get hit like 50,000 query rows limit .

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .