You need to sign in to do that
Don't have an account?
Jerun Jose
Pass value to finish method in batch apex
Hi,
Is there a way to be able to pass values from the execute method to the finish method.
I think this can be done using the database.stateful interface, but I do not need to maintain state of all the variables that I am using in my execute method. I only need to use one ID value which will be identified using my execute methods.
Please let me know if there is someway of doing this.
The interface to finish() is defined as:
as this is called from SFDC, not your code. The global variables in your batchable class provide the intercommunication 'vehicle' between start() - execute() - finish()
All Answers
Try using a Static Field if you want it just for that transaction else you would have to Stateful as per my understanding.
This issue is covered in depth with an example in the Apex Developer's Guide in the section entitled 'Using State in Batch Apex'
The batchable class must also implement the DatabaseStateful interface and then you can use instance variables defined as global to maintain state. The code example shows how to do this.
If you look at the example, where the doc has:
global Integer Summary;
you would replace with
global ID myglobalId;
Initialize this in the constructor, perhaps by passing it in as an argument to the constructor
The interface to finish() is defined as:
as this is called from SFDC, not your code. The global variables in your batchable class provide the intercommunication 'vehicle' between start() - execute() - finish()