Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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}" />  
</apex:form>
</apex:page>

Controller

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;
 }
share|improve this question

http://www.tehnrd.com/batch-apex-status-bar/

This is a nice Batch Status bar you might want to look into


Update on 2016-01-19

The link above is dead, 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?

share|improve this answer
    
Thats a really good find! – developer__c Jun 8 '15 at 14:06
    
the link is taken down! What is the solution for this? – sfdcFanBoy Jan 19 at 3:32
    
Answer is updated – Scott Pelak Jan 19 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 .

share|improve this answer
    
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 '12 at 4:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.