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
bbrantly1bbrantly1 

Return Results from Batch

I'm trying to figure out if there is a way to return some "results" from a batchable interface?  Example:

 

Batch Code:

global class QuickBatch implements Database.Batchable<sObject>, Database.Stateful{ global final String Query; global string Summary; global QuickBatch(String q) { Query=q; Summary = ''; } global Database.QueryLocator start(Database.BatchableContext BC){ return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<sObject> scope) { for(sObject s : scope) { Summary += ',' + s.get('id'); } } global void finish(Database.BatchableContext BC){ } }

 

Apex Controller

 

public with sharing class BatchTest { public BatchTest() { rValue = 'started'; } public QuickBatch q = new QuickBatch('SELECT ID FROM ACCOUNT'); public void Start() { string batchprocessid = Database.executeBatch(q,1); } public string rValue {get;set;} public void GetResultsFunction() { rValue = 'DONE:' + q.Summary; } }

 

For testing I have created a Visualforce page which calls "Start" from a CommandButton.  I then wait for the job to finish, then click a second button which executes "GetResultsFunction" and ReRenders an OutputPanel.

 

I never get a return from q.Summary though.  I know the jobs run asynchronously, but I was hoping it was somehow "store" the results so they can be obtained.  It doesn't look like it is possible. 

 

Does anyone know how to do this? if it can't be done, what is the best way to obtain results from a batchable interface that say does a mass calcuation of some type? store a temp record?

 

Thanks for any and all help.