You need to sign in to do that
Don't have an account?
Future method cannot be called from a future or batch method
Hi,
I have an after update trigger on Account. When a field is updated to 0, the account shud be deleted from the system. For that, i have the after update trigger and then a @ future class. It is giving me the follwing error like
Future method cannot be called from a future or batch method.
I checked the static boolean variable also to avoid recursive calls. Please check my code below and suggest.
1.trigger
SME_LogoDelete onAccount (afterupdate)
{
if
(Utility.isFutureUpdate != true){
Account[] newacc=trigger.NEW;
Account[] oldacc=trigger.OLD;
List<String> dellist=
newList<String>();
for(integer i=0;i<newacc.size();i++)
{
if(newacc[i].Number_of_Accounts__c!=oldacc[i].Number_of_Accounts__c && newacc[i].Number_of_Accounts__c==0)
{
dellist.add(newacc[i].id);
}
}
system.debug('******SME_LogoDelete22222*******'+dellist);
SME_LOGODelete.deletelogo(dellist);
}
}
2. Static boolean check
public class Utility{
public static boolean isFutureUpdate=false;
}
3. Future call
global class SME_LOGODelete {
@future
public static void deletelogo(List<String> dellist)
{
List<Account> deletelist=new List<Account>([select Id from Account where ID=: dellist]);
Utility.isFutureUpdate = true;
System.debug('Method called with: '+dellist);
DELETE deletelist;
}
}
Thanks
There is already standard method you can use to find out the current request type:
if(System.isFuture()) { }
Thank you for the reply.
So, ne need of static boolean check if i check this in my trigger. Is it the same you are suggesting here.
if(System.isFuture()) {
....
}
But my problem is whenever the field is updated to zero, the account should be deleted.
This trigger should send the data to Future method and that will delete the account.
Which is not happening when i put this condition in my trigger.
No triggers on delete event.
17:31:28.217 (217499000)|CODE_UNIT_STARTED|[EXTERNAL]|01qN0000000CfwP|SME_LogoDelete on Account trigger event AfterUpdate for [001N0000005RI1I]
17:31:28.217 (217822000)|SYSTEM_METHOD_ENTRY|[4]|System.isFuture()
17:31:28.217 (217886000)|SYSTEM_METHOD_EXIT|[4]|System.isFuture()
17:31:28.995 (217915000)|CUMULATIVE_LIMIT_USAGE
17:31:28.995|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 3 out of 200
Number of query rows: 3 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 2 out of 150
Number of DML rows: 2 out of 10000
Number of code statements: 164 out of 1000000
Maximum heap size: 0 out of 12000000
Number of callouts: 0 out of 0
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 0
17:31:28.995|CUMULATIVE_LIMIT_USAGE_END
17:31:28.217 (217985000)|CODE_UNIT_FINISHED|SME_LogoDelete on Account trigger event AfterUpdate for [001N0000005RI1I]
Hi,
I am not getting any error message. But the code in my future methos is not getting executed. In this scenario, when the deletelogo method is called from my trigger, account shud get deleted from the system.
/*****method call in trigger
SME_LOGODelete.deletelogo(dellist);
/*****************future method below
global class SME_LOGODelete {
@future
public static void deletelogo(List<String> dellist)
{
List<Account> deletelist=new List<Account>([select Id from Account where ID=: dellist]);
// Utility.isFutureUpdate = true;
System.debug('Method called with: '+dellist);
DELETE deletelist;
}
}