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
streetstreet 

Can we call Batch apex class on custom button click.

Can we call batch apex class which implements Database.Batchable. on button click(custom button) or visual force tab?

 

Avi646Avi646

yes we can do that by executing a JavaScript to call a Global class that will inturn run your Batch apex class.

streetstreet

Can u give me the sample code blocks..

Avi646Avi646
global class FinalizeTempLNK {
  WebService static void ExecuteFinalizeTemp(
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
sforce.apex.execute("FinalizeTempLNK ","ExecuteFinalizeTemp",{ });

 

){
    String query = 'Select Id,isTemp__c from Cheque__c' ;
      Finalize_Temp batchApex = new Finalize_Temp (query );
        ID batchprocessid = Database.executeBatch(batchApex);
  }

 Above is the globall class to call the batch apex class.