I want to display a list of records processed out of a batch process on a Visuaforce page for user operation.
The Batch process returns a list of records but the list is not passed to the VF controller. The list shows empty when debugged in the Vf controller. I do realise that the batch process runs asynchronously, but the requirement is really critical.
Please reply as soon as possible. Any pointers will be highly appreciated. Thanks in advance.
Implement Database.Stateful in your Batch Apex class.
Create a Map or List variable which is Global and which will be used to store the records processed.
Also create a Global Boolean variable that you will use in the Finish method of Batch Apex and turn it true when all processes are finished.
In your VF page, you have to use window.setInterval function and invoke a controller method at regular intervals that will check whether the Boolean variable in Batch Apex has turned true.
If its true then you can use the Map or list you defined in Batch Apex.
Implement Database.Stateful in your Batch Apex class.
Create a Map or List variable which is Global and which will be used to store the records processed.
Also create a Global Boolean variable that you will use in the Finish method of Batch Apex and turn it true when all processes are finished.
In your VF page, you have to use window.setInterval function and invoke a controller method at regular intervals that will check whether the Boolean variable in Batch Apex has turned true.
If its true then you can use the Map or list you defined in Batch Apex.
Can you please provide some sample code how to declare the variable in the batch apex. I have a requirement to get the count of records processed by batch apex.
andhra123, did you ever figure this out? I'm creating the same thing....a Batch Apex (Stateful) in which I will need to store maps and Lists to hold values and then call the batch from a visualforce page.
Implement Database.Stateful in your Batch Apex class.
Create a Map or List variable which is Global and which will be used to store the records processed.
Also create a Global Boolean variable that you will use in the Finish method of Batch Apex and turn it true when all processes are finished.
In your VF page, you have to use window.setInterval function and invoke a controller method at regular intervals that will check whether the Boolean variable in Batch Apex has turned true.
If its true then you can use the Map or list you defined in Batch Apex.
All Answers
Implement Database.Stateful in your Batch Apex class.
Create a Map or List variable which is Global and which will be used to store the records processed.
Also create a Global Boolean variable that you will use in the Finish method of Batch Apex and turn it true when all processes are finished.
In your VF page, you have to use window.setInterval function and invoke a controller method at regular intervals that will check whether the Boolean variable in Batch Apex has turned true.
If its true then you can use the Map or list you defined in Batch Apex.
Hi Imran,
Can you please provide some sample code how to declare the variable in the batch apex. I have a requirement to get the count of records processed by batch apex.
Thanks
andhra123, did you ever figure this out? I'm creating the same thing....a Batch Apex (Stateful) in which I will need to store maps and Lists to hold values and then call the batch from a visualforce page.
Hi chubsub,
See the message posted by Imran Mohammed. I applied same logic to get the count of records processed by apex job.
it would be helpful for you too.
All the best.
I'm facing the same problem,
I tried the solution suggested by Imran but it didn't work for me.
Can you please give me some more information.