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

Updating a batch job only after the last batch has been processed.

Is it possible to only update after the very last batch has been proccessed in a batch apex job?  I'm using a stateful batch to determine the mean, UCL, and LCL of a large dataset.  What I was hoping to do was have this job run every night, and by tracking the field history be able to report/graph on the moving average of these values.


My first thought was to assign Database.countQuery / [batchsize] to a variable allowing me to check if i was on the last batch within the execute method.  Unfortantly, it doesn't appear that this is allowed.


Any suggestions would be greatly appreciated.




You can query the current batch job and get the no.of batches. As you are using the stateful batch you can find out which one is the last job and then update the last record.