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
sami amisami ami 

Future method cannot be called from a future or batch method

hi

 

I have a trigger which will be fired under some condition.

It works perfect and fine if i just give insert.

If i also include update,I get error :

How can i get ride of this?

please help

System.AsyncException: Future method cannot be called from a future or batch method

Starz26Starz26

structure your trigger like this

 

trigger XXXXX on XXXX (XXX insert, XXX update){

 

if(trigger.isInsert){

....Your code to run during insert

}else if(trigger.isUpdate({

....Your code to run during update

}

 

 

}

sami amisami ami
But my use case is different.
First case: When i create a case in salesforce ,I am creating a case in my third party (integration)when a particular checkbox is created.
When i check the checkbox,its calling a future call class from a trigger and the class stuff is being executed and case is also creating in my third party.
later if any updates happen in my salesforce case it will be updated in my third party too.
my another case: If i create a case and later come and update the checkbox to true,then it should create a case in my third party.
later if i make any update in that case,changes should be made in that created case,(Same as above)
If i use after insert,after update i am getting above error.
how can i solve this?
sami amisami ami
Argh!!!!!!! I did something like this using this http://www.tehnrd.com/apex-flow-control-preventing-infinite-loops/

It works...I am able to create cases but each time trigger fires,cases are being duplicated .Any help:(