0

I'm trying to call a method which do an api call. But I'm getting an error because this method get call through the process ran by batch and this is getting schedule from trigger. So even if i directly call the API calling method it gives me an error 'Callout from triggers are currently not supported'. And when I call future method then it says future method cannot be called from batch.

Please help in this.Thank you.

0

The two errors you are receiving are both correct.

Callout from triggers are currently not supported

This is accurate; you cannot make callouts directly from triggers.

future method cannot be called from batch.

This is also accurate. As you'll see in the Batch Apex documentation,

To use a callout in batch Apex, specify Database.AllowsCallouts in the class definition. For example:

global class SearchAndReplace implements Database.Batchable<sObject>, 
   Database.AllowsCallouts{
}

The scheduler aspect is irrelevant to both errors, although scheduling a batch from a trigger is inherently a bit risky unless you can include very careful logic to avoid scheduling the batch repeatedly.

  • Can you tell me a better approach to handle this kind of scenario – Ravi Roy Feb 11 at 3:51
  • You would need to write quite a bit more detail in your question, Ravi Kant. Or you may need to add a different question. The direct answer to what you're asking is that you need to specify Database.AllowsCallouts, as noted above. – David Reed Feb 11 at 3:52

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.