You need to sign in to do that
Don't have an account?
global action button to call batch job
how to add a global action or button, that by clicking on it, it will start the job batch ?
here is the code to start the job in console
Id batchJobId = Database.executeBatch(new FindAccounts(), 100);
here is the code to start the job in console
Id batchJobId = Database.executeBatch(new FindAccounts(), 100);
If this doesn't work share your JS button code and the class ValidateBefore.
All Answers
Unfortunately it is not possible to call a batch class from Global/Quick action. However you can create a custom buttom(Javascript button) which you can use to call your class.
It will look something like this:
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);
}
Now call your ABC class in the javascript button.
if i create a new class called calljob how you will put that together ? in the button ?
In that code, there is a class called ValidateBefore with a method called validate. In this validate method, the batch apex is called.
Now in your Javascript button, we write:
sforce.apex.execute("ValidateBefore","validate",{"{!Account.Name}"});
Syntax is:
sforce.apex.execute("YOUR CLASS NAME", "YOUR METHOD NAME",PASS YOUR PARAMETERS IN JSON);
Make sure your method is of webservice type.
Apex class methods can be exposed as custom SOAP Web service calls. This allows an external application to invoke an Apex Web service to perform an action in Salesforce.
global with sharing class ValidateBefore {
webService static String validate(String param) {
Database.executeBatch(new FindAccounts(), 100);
}
You this code: And in JS button, use this line:
sforce.apex.execute("ValidateBefore","validate",{});
and yes we do use namespace.
thanks Narender
In that case, use this code: Also, please make sure that 'ValidateBefore' class is declared as global and 'validate' method is prefixed with webservice keyword.
If this doesn't work share your JS button code and the class ValidateBefore.
Are you still getting the same error?
If yes then try changing the API version to 43 like this:
{!REQUIRESCRIPT("/soap/ajax/43.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/43.0/apex.js")}
Let me know if it helps
I have a emailed you. Kindly check your mail.
Thanks