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
NaziNazi 

How to call batch class inside apex class

How to call batch class inside apex class method.Is there any way to call ? if so please give some example.
Best Answer chosen by Nazi
Apoorv Saxena 4Apoorv Saxena 4
Hi Nazira,

You can call your batch class from a method inside your apex class using following code:
 
public void yourMethodName(){

    YourBatchClassName bcn = new YourBatchClassName() ;
    ID batchprocessid = Database.executeBatch(bcn);

}

Hope this helps!

Please mark this question as Solved if this answers your query so that others can view it as a proper solution.

Thanks,
Apoorv

All Answers

Apoorv Saxena 4Apoorv Saxena 4
Hi Nazira,

You can call your batch class from a method inside your apex class using following code:
 
public void yourMethodName(){

    YourBatchClassName bcn = new YourBatchClassName() ;
    ID batchprocessid = Database.executeBatch(bcn);

}

Hope this helps!

Please mark this question as Solved if this answers your query so that others can view it as a proper solution.

Thanks,
Apoorv
This was selected as the best answer
NaziNazi
Thanks Apoorv. It works.
Rowallim TechnologyRowallim Technology
Hi Nazira

here's class method to run batch paex from apex class :


Batch_name batchJob = new Batch_name();
ID batchprocessid = Database.executeBatch(batchJob);

If you find it useful. Mark it best.
Thanks