I need to show a alert message after the batch process is completed. For that i have create a static boolean varible in a class and in my batch process finish i am calling this varible and changing the value of the boolean varible, when the process is completed. I am using a apex button to run the batch process. The value of the boolean is get changed but i am not able to show the message when the process is completed. my batch file

 global void finish(Database.BatchableContext BC)
    System.debug('Batch Process Completed in finish 1');
    BatchUpdate_info.Updateresult = true;
    System.debug('Batch Process Completed in finish 2');
    system.debug('Batch process result ' + BatchUpdate_info.Updateresult);

} static var

public class BatchUpdate_info { 

public static boolean Updateresult = false; }

VF page to run the batch file

<apex:page controller="ctrl_ConatctBatch">
<apex:messages />
<apex:form >
<apex:commandButton value="Run Batch Process" action="{!getRunBatch}" />  


public class ctrl_ConatctBatch

public String getRunBatch() 
     contact_BatchProcess cb = new contact_BatchProcess ();
     Database.executeBatch(cb, 200);
     System.debug('Result : In getRunBatch function');
     if(BatchUpdate_info.Updateresult == true){
        System.debug('Batch Process Completed');
        ApexPages.Message dupeMsg = new      ApexPages.Message(ApexPages.Severity.INFO,'Batch Process Completed');
        BatchUpdate_info.Updateresult = false;
        System.debug('Batch Update result ' + BatchUpdate_info.Updateresult);

     return null;

2 Answers 2


Update on 2016-01-19

The link previously shared was of un secure site so removed that, so here's briefly what to do:

  1. Get the Id of the Async Apex Job record: Id batchId = Database.executeBatch(myBatchClass);
  2. Query AsynxApexJob to get information about the Batch Process particularly the Status, Extended Status, Job Items Processed, Number of Errors, and Total Job Items. For more information about AsyncApexJob, see the DeveloperForce Workbench.
  3. Update your Visualforce Page or Lightning App with the queried AsyncApexJob data. There are many UIs available for Progress Bars particularly using HTML5. Essentially you want to show the % done as Job Items Processed / Total Job Items. And don't forget to have a way to show if the Batch failed (like turning the Progress Bar red or something -- maybe display the Status and Extended Status...). Links about Progress Bars: HTML5 Progress from CSS Tricks, Bootstrap 3 Progress Bars

Update on 2016-01-22

Found an answer of mine that has the code from the original link:

Best practices for monitoring Scheduled Apex and Batch Apex?

  • Thats a really good find! Jun 8, 2015 at 14:06
  • the link is taken down! What is the solution for this?
    – sfdcFanBoy
    Jan 19, 2016 at 3:32
  • Answer is updated Jan 19, 2016 at 16:30

The better approach for this would be use an email alert to send to the User once a batch is completed .

If you want on the page an action poller or streaming API is the only way to detect this and show on to the page the moment batch completes .

  • Yes i know to use email, but i like to show a message on VF page after the batch process is completed, is this possible.
    – AnuRaj
    Dec 17, 2012 at 4:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .