4

I was attempting to call a future callout method from a trigger and am getting the error that a future method can not be called from a future or batch method. The trigger is being called on insert of a ContentDocumentLink object, which is inserted by a managed package in our org (so I can't see what it's doing). I am only calling one future method and no batch methods. Am I ok to assume the managed package is using a future method to insert the document link? Or, even if it is, would it not cause this issue?

If it is an issue, any suggestions on the best way to go about writing a trigger that implements a callout knowing a batch/future method will start the trigger?

9

If your code is already asynchronous, you don't need to use a @future method to call out. So you can add checks for this sort of thing.

public static void makeCallout(/*params*/)
{
    if (!system.isFuture() && !system.isQueueable() && !system.isBatch()
    {
        makeCalloutAsync();
    }
}
@future
static void makeCalloutAsync(/*params*/)
{
    makeCallout(/*params*/);
}

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.