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
JSchneiderJSchneider 

Custom Link to run batch APEX job?

I have a very simple command that I plug into the Develope Console and it works great.
batchMaintenanceCalculator b = new batchMaintenanceCalculator();
    database.executeBatch(b,25);
I'ld like to figure out a way that I can create a url that will do the same.  So other users can execute without the Developer Console
 
Best Answer chosen by JSchneider
Amit Chaudhary 8Amit Chaudhary 8
Please check below blog . I hope that will help  you.
http://sfdcintegration.blogspot.in/2014/01/execute-batch-apex-from-java-script.html


You can batch job below java scipt button.


{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
 {!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
  var scr="batchMaintenanceCalculator c = new batchMaintenanceCalculator (); " +
         " Database.executeBatch(c, 5); ";
  var result = sforce.apex.executeAnonymous(scr);
   alert("The Batch is Running");

Please let us know if this will help you.

Thanks,
Amit Chaudhary
amit.salesforce21@gmail.com

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please check below blog . I hope that will help  you.
http://sfdcintegration.blogspot.in/2014/01/execute-batch-apex-from-java-script.html


You can batch job below java scipt button.


{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
 {!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
  var scr="batchMaintenanceCalculator c = new batchMaintenanceCalculator (); " +
         " Database.executeBatch(c, 5); ";
  var result = sforce.apex.executeAnonymous(scr);
   alert("The Batch is Running");

Please let us know if this will help you.

Thanks,
Amit Chaudhary
amit.salesforce21@gmail.com
This was selected as the best answer
AmrenderAmrender
Hello 

I never tried this. But just a thought.

Create a simple VF page like below
<apex:page controller="BatchMaintenanceCalculatorExecute" action={!runBatchMaintenance}>
</apex:page>

Create BatchMaintenanceCalculatorExecute class
public class BatchMaintenanceCalculatorExecute {
	public PageReference runBatchMaintenance() {
		batchMaintenanceCalculator b = new batchMaintenanceCalculator(); 
		​database.executeBatch(b,25);
	}
}

Now you have two options to run this

1) Create a Visualforce Tab for above VF page and grant the tab premission to the profiles
2) Create a Custom Link  Setup->Customize->Home->Custom Link. Your VF page will be the Content Source for this Custom Link. Display this link in the sidebar component

Let me know if it helps.


Regards
Amrender