1

We are trying to track a field change on a record of a managed package object, based on this we are calling out one of our downstream application with rest call.

Step 1- A Managed package batch job is updating a field on Managed package object record.

Step 2 - Taking this a triggering action we are calling one of our downstream application using future methods from trigger.

Step 3 - The managed package job is failing with Too many future calls: 1

We have debugged the execution, observed future call is getting executed only once and the whole code is bulkified, generally when we call asynchronous to future methods below error will come

First error: Future method cannot be called from a future or batch method: WebPortalCLBatchJobStatus.notifyJobStatus(String)     

But couldn't figure out what is this Too many future calls: 1 error

  • Are you performing API call in trigger? – Mr.Frodo Nov 10 '16 at 12:28
  • Yeah if you're already in a trigger context, you will see Limits.getLimitFutureCalls() == 0. – Adrian Larson Nov 10 '16 at 12:40
1

In your code that is calling the future method you will need to wrap it in:

if(!system.isFuture() || !system.isBatch()){
   //trigger your future method
}

If you need to execute your future method as part of this batch process you will have to call the method directly. You can do it by constructing your future as such:

@future
public static myAsyncMethod(Id i){
   myMethod(i);
}

public static myMethod(Id i){
   ....
}

Then in your batch execute myMethod which will do the work skipped by the batch and future check above

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.