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
sites1.3909952495827087E12sites1.3909952495827087E12 

future method cannot be called from a future or batch method salesforce

I  Hav one batch class on Accoun running every hour. and  on account object one more trigger calling the @future method in class.


wen i run te batch iam getting this error. How to avoid thsi error.


 
Best Answer chosen by sites1.3909952495827087E12
SwaroopaSwaroopa
Hi,


There is a salesforce limitation that you can not call future methods from batch. To avoid this error you can keep one flag in batch class and check that flag in Account trigger, if it is coming from batch do not call that future method.

Batch class

public static accountBatchFlag = false

Before performing any updates/inserts you can make this flag as true in batch


In trigger you can check the condition if accountBatchFlag is false then call future method. this way you can avoid error

All Answers

SwaroopaSwaroopa
Hi,


There is a salesforce limitation that you can not call future methods from batch. To avoid this error you can keep one flag in batch class and check that flag in Account trigger, if it is coming from batch do not call that future method.

Batch class

public static accountBatchFlag = false

Before performing any updates/inserts you can make this flag as true in batch


In trigger you can check the condition if accountBatchFlag is false then call future method. this way you can avoid error
This was selected as the best answer
sites1.3909952495827087E12sites1.3909952495827087E12
Thanks for your answer Swaroopa, Will try tis and let u know its working or not.