You need to sign in to do that
Don't have an account?
Carolina W 2
Error: Future method cannot be called from a future or batch method
Hi! How can I fix this error?
System.AsyncException: Future method cannot be called from a future or batch method
I guess this happen because my future method is an update and the Trigger is called in looping. So I created the boolean runTrigger to not run the trigger when it's false, but I don't know how to do it exactly.
P.s: It need to be a future method
Class
public class AccountUpdate { public static boolean runTrigger = true; //I create this variable to stop the looping, but I don't know where I have to put 'runTrigger = False;' //This future Mehod update the Account Name @Future public static void doAutomaticExternIntegration(List<Id> ids) { List<Account> accountsFound = [SELECT ID, Name FROM Account WHERE Id IN :ids]; List<Account> accountToUpdate = new List<Account>(); for (Account acc: accountsFound){ acc.Name = 'ABCD'; accountToUpdate.add(acc); } update accountToUpdate; } //This class runs the Future Method above public static void runFutureMethod (List<Account> accs){ if(!runTrigger){ return; }else{ List<Id> accountIds = new List<Id>(); for(Account acc : accs){ AccountIds.add(acc.Id); } doAutomaticExternIntegration(accountIds); } } }Trigger
trigger AccountTrigger on Account (after update) { AccountUpdate.runFutureMethod(trigger.new); }
Thank you @Swetha ! The solution:
All Answers
Does the example code mentioned in the post https://salesforce.stackexchange.com/questions/102196/error-future-method-cannot-be-called-from-a-future-or-batch-class/102200 help?
If this information helps, please mark the answer as best.Thank you
Thank you @Swetha ! The solution: