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
sultansultan 

can we call batch apex class from Trigger?

Best Answer chosen by sultan
Vinit_KumarVinit_Kumar
Yes you can,

In your Trigger code something like below :-

// BatchClass is the name of batchclass
BatchClass bh = new BatchClass();
Database.executeBacth(bh);
My only concern is that the Trigger would fire on the DML events and that would invoke the Batch.Do you want to run batch as many times as the Trigger would fire ??

If this helps,please mark it as best answer to help others :)

All Answers

Vinit_KumarVinit_Kumar
Yes you can,

In your Trigger code something like below :-

// BatchClass is the name of batchclass
BatchClass bh = new BatchClass();
Database.executeBacth(bh);
My only concern is that the Trigger would fire on the DML events and that would invoke the Batch.Do you want to run batch as many times as the Trigger would fire ??

If this helps,please mark it as best answer to help others :)
This was selected as the best answer
hu yanghu yang
You can use '@future'
Matrix ReturnsMatrix Returns
can we call trigger from batch class