1

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){
        OCTAutomationProcessBatchHandler.performLogic(octBatchInfo);
    }
}

global void finish(Database.BatchableContext BC) {
}

Javascript code:

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 

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"); 

if(records.length>0){ 
window.alert("The batch job is currently executing. Please wait."); 
} 
else{ 
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
1

maybe change:

var batchid=sforce.apex.execute

to

var batchid=sforce.apex.executeAnonymous

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

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.