Skip to main content
sakthi dasan preguntó en #Apex
I'm new to salesforce Please explain these question

Is it advisable to call batch class from trigger? If Yes, Why? If No, Why?
1 respuesta
  1. 17 mar 2016, 05:04
    Hi Sakthidasan,

    A batch apex can be called from a class as well as from trigger code. But, we have to be very very carefull while calling a batch apex from trigger.

    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 ?? Then you can proceed, but my personal openion is not to go with it.

    Please follow the below links on the same post:

    http://sfdcsrini.blogspot.com/2014/06/how-to-execute-batch-apex-using-apex.html

    https://developer.salesforce.com/forums/?id=906F0000000AarkIAC

    https://developer.salesforce.com/forums/?id=906F00000008zgyIAA

    http://salesforce.stackexchange.com/questions/92047/call-schedulable-batch-class-from-trigger-instead-of-any-schedule

    http://www.cloudforce4u.com/2013/11/call-batch-apex-from-trigger.html

    http://theblogreaders.com/how-to-execute-batch-apex-using-apex-trigger/⌗.Vuo5DOYohv5

    http://www.infallibletechie.com/2012/05/how-to-run-batch-apex.html

    Batch Apex Best Practices

    http://sfdcrocket.blogspot.com/2013/12/batch-apex-best-practices.html

    Please do let me know if it helps you.

    Regards,

    Mahesh
0/9000