I have a single batch class, which calls a number of other batch classes when it runs. I'd like to be able to run this batch by pressing a custom javascript button. I've written a button to accomplish this (Based off an example), but it fails with the error:

not ars found...

Here's the Batch code:

global class OCTAutomationProcessBatch implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC) {
    string query = 'SELECT Name, Source_Table__c , Destination_Table__c , Source_Query__c, Criteria_Field_Key__c from OCT_Batch_Information__mdt' +
                    'Where Want_To_Process__c = True';
    return Database.getQueryLocator(query);

global void execute(Database.BatchableContext BC, List<OCT_Batch_Information__mdt> scope) {
    for(OCT_Batch_Information__mdt octBatchInfo : scope){

global void finish(Database.BatchableContext BC) {

Javascript code:


var apexBatch= sforce.connection.query("SELECT Id FROM ApexClass WHERE Name ='OCTAutomationProcessBatch'"); 

recordsclassid= apexBatch.getArray("records"); 

var checkBatchRunningRecords= sforce.connection.query("SELECT ApexClassId, status FROM AsyncApexJob WHERE ApexClassId ='"+recordsclassid[0].Id+"' AND Status NOT IN ('Completed','Aborted','Failed')"); 

records= checkBatchRunningRecords.getArray("records"); 

window.alert("The batch job is currently executing. Please wait."); 
window.alert('The batch job has started.'); 
var batchid=sforce.apex.execute("OCTAutomationProcessBatch",{}); 

  • 3
    Can you post the error message verbatim? – Eric Jun 7 '17 at 19:38
  • args not specified – CrispuSF Jun 8 '17 at 12:20

maybe change:

var batchid=sforce.apex.execute


var batchid=sforce.apex.executeAnonymous

The first one needs the apex class to be a web service.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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