You need to sign in to do that
Don't have an account?

Custom Button to run batch class
Hi Guys,
I need your help that how can I create a custom button on list view to run the batch class.
Right now I go to developer console and click on Debug and click on Open Execute Anonymous Window and then I enter Database.executeBatch(new CreateOrderBatch(),1); and then execute it. When I execute it then it makes a API call.
Is there a way I can just click on the Custom Button on List View and it makes API calls instead of going Developer Console?
Thanks!
I need your help that how can I create a custom button on list view to run the batch class.
Right now I go to developer console and click on Debug and click on Open Execute Anonymous Window and then I enter Database.executeBatch(new CreateOrderBatch(),1); and then execute it. When I execute it then it makes a API call.
Is there a way I can just click on the Custom Button on List View and it makes API calls instead of going Developer Console?
Thanks!
You can also have a look at Question 157 here. (http://www.jitendrazaa.com/blog/salesforce/apex-interview-question-salesforce-part-16/)
Apex Class:
global with sharing class ValidateBefore {
webService static String validate(String param) {
Database.executeBatch(new CreateOrderBatch(),1); // this is your call
}
Custom Button:
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
var result = sforce.apex.execute("ValidateBefore","validate",{"{!Account.Name}"});
if(result == 'OK') {
window.location = '/{!Account.Id}';
} else {
alert(result);
}