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

Batch Apex + Visualforce Controller(passing list of records)


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.




Cory CowgillCory Cowgill

Batch Apex does not return a list of records. Database.execute(batch,scope) only returns the ID of the Batch Job that was placed in the Queue.


Futhermore, as you note, it is Asynchronous. There is no guarantee of when it will execute in the queue, or when it will finish. Creating a VF Page to view the output of a Batch Apex process is not going to work at all like you described.


You can look at performing this functionality in this type of pattern.


1. User requests  batch processing by clicking your VF Page Button, which invokes the Batch Process. This gives them a screen, "Processing Batch...... Email will be sent when finished".

2. Upon Batch Finish method, send an email to the user with a Link to your VF Page which will display the processed records.

3. In the Controller for the VF Page, you need to Query to get the records processed (NOTE: You will be limited to 10,000 records as this is Controller).

4. You would need to establish some sort of criteria to establish what documents where processed in the Batch. You could create a custom field which holds the BatchID of the processing batch on the records, then query for all records processed by the Batch.


Hi Cory,

I'm pretty new to Apex.. could you tell me how to for the records processed after completion of a batch job? I am looking to process the records and call a webservice after the completion of the job. How can we achieve this?