Activity Forums Salesforce® Discussions We can't call future from future method but we can call batch class from another batch whereas both are asynchronous?

  • We can't call future from future method but we can call batch class from another batch whereas both are asynchronous?

    Posted by Suraj on April 5, 2017 at 1:52 pm

    We can't call future from future method but we can call batch class from another batch whereas both are asynchronous.Why?

    Manpreet replied 7 years, 8 months ago 2 Members · 1 Reply
  • 1 Reply
  • Manpreet

    Member
    April 5, 2017 at 4:16 pm

    Hi Suraj,

    You cannot call a method annotated with future from a method that also has the future annotation. Nor can you call a trigger from an annotated method that calls another annotated method.

    1.) There are no limits on the number of @future methods you can have inside of a class, however there are limits on the number of future calls you can make in a given transaction (50 calls per transaction)
    2.) Because it's a limtiation of the system. If I had to take a guess, it's to keep the system from being flooded with forked calls (look at the bash fork bomb for what could happen)
    3.) Yes, you can write tests just like you normally would. The only stipulation is that the future calls will not occur until you make a Test.startTest or Test.stopTest call
    4.) All future methods are Asynchronous but not all async calls are future. For example, batchable and scheduled apex are async.AJAX by definition is asynchronous (Asynchronous JavaScript And XML)

    Thanks.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos