Activity Forums Salesforce® Discussions How can we call future method from Salesforce batch apex?

  • Anurag

    Member
    July 17, 2018 at 11:57 am

    Hello Prachi,

    We cannot call future methods from any batch class or any other future class because both are asynchronous methods and the exact time of their execution is not known so adding an asynchronous method to an already existing one is not considered best practice. Besides, it is not allowed in Salesforce.

  • Avnish Yadav

    Member
    September 10, 2018 at 6:46 am

    Hello Prachi,

    Salesforce doesn't allow a future method to be called from another future method or a batch job. Before calling your future method, you should check if a future or batch job is already running. This would be a best practice for any code you ever write that calls a future method. Good news is that it's very easy. Example below:

    if(System.IsBatch() == false && System.isFuture() == false){ 
        // make your future call here 
    }

    Thanks.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos