You need to sign in to do that
Don't have an account?
System.AsyncException: Future method cannot be called from a future or batch method
Hi,
I am getting this error when I make REST calls .
System.AsyncException: Future method cannot be called from a future or batch method: Myfutureclass.method(LIST<Id>)
This is a trigger which calls that class which has future method and calls REST calls.
trigger checkcase on Case (after insert,after update) {
List<Id> caseIds = new List<Id>();
for(Case c : Trigger.New)
{
if(c.Checkbox__c)
{
caseIds.add(c.Id);
System.debug('*********Caseid'+CaseIds);
}
}
System.debug('***********Trigger.new'+trigger.new);
System.debug('***********Trigger.old'+trigger.old);
if(caseIds.size() > 0){
if(Trigger.isinsert){
Myfutureclass.method(caseIds);
}
if(trigger.isUpdate ){
if(trigger.old[0].Checkbox__c){
Myfutureclass.method(caseIds);
}
}
}
}
Please correct me what i am missing??Please
Hi,
The possible reason is that your Future method is trying to do an update on case object which is causing the trigger to fire again....(recursive trigger)
You need to check if the trigger is being fired from the future method, add the below line as your first line of trigger.
But when i insert a case,Its creating two cases in my third party.
When i update existing case and mark checkbox true,its not even executing this trigger.
What might be my mistake?
Hi,
I'm not sure why its creating two cases in your third party system...do you mind sharing code for your webservices class ?
Also, Few things that I have noticed in your trigger...
On this is running on Update you are checking values from trigger.old..i.e
I don't this will execute the code inside if condition when you select Checkbox__c field, because trigger.old will have unselected value. + When you use trigger.old[0], this means it will only check the value for one record. Hence these could be the two reasons that its not executing the logic inside the second If statement.
Can you also tell me exactly what you want to do in your trigger in simple plain text and I may suggest you some thing.