+ Start a Discussion
Muhammad Jawwad 16Muhammad Jawwad 16 

How to execute Batch Apex form Visualforce Page?

I have three batch classes, I want to execute all three batch classes through button click using visualforce page at the same time.
LoanofficerBatch lob = new LoanofficerBatch(); 
        RealtorBatch rb = new RealtorBatch(); 
        BuilderBatch bb = new BuilderBatch(); 

please help
Best Answer chosen by Muhammad Jawwad 16
Om PrakashOm Prakash
You need to write above code in a method of Apex class, then call that apex method from Command button of visualforce page.
public class BatchApexController(){
      public void callBatch(){
         // Your code here to execute the batch class/es
<apex:page controller="BatchApexController">
  <apex:form >
    <apex:commandButton action="{!callBatch}" value="Submit Batch" />

This discussion will give you more details https://developer.salesforce.com/forums/?id=906F0000000MIOnIAO