+ Start a Discussion
Ken KoellnerKen Koellner 

callout about from queueable execute()

Tried doing a callout from an execute method in a queueable class and go the @future error -
Callout not allowed from this future method. Please enable callout by annotating the future method. eg: @Future(callout=true)
07:13:51.752 (8701449752265601)|SYSTEM_METHOD_EXIT|[1263]|System.Http.send(ANY)
Is there a way to annotate the execute with "(callout=true)".

I sounds like what i want to do may be doable if there's just some syntax to get the annotation.

 
ShashankShashank (Salesforce Developers) 
Yes, you should be able to mark a future method as a callout using the syntax mentioned here: https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm
Ken KoellnerKen Koellner
Shashank, I don't think you understood the question.  I'm not coding an @future.  I'm coding an execute() method for the new "queueable" interface.  I don't think you can use the @future syntax on that method.  For one thing, the queueable execute() method is an instance method, not a static method.  And @future requires that the method be static.

I'm thinking that there must be some other syntax that designates a queueable execute() as having a callout.  But I don't see anything in the documentation.

 
ShashankShashank (Salesforce Developers) 
You have to implement the "Database.AllowsCallouts" interface along with the "Queueable" interface to enable callouts, just like in batch apex and scheduled apex.

Something like this:
 
public class AsyncExecutionExample implements Queueable, Database.AllowsCallouts {
    public void execute(QueueableContext context) {
        //your code including the callout     
    }
}

 
Javier VazquezJavier Vazquez
Your solution is perfect, Shashank. I think Ken Koellner has been rude, but I am here to congratulate you :)
Lee Hildebrand 6Lee Hildebrand 6
This thread is pretty old, but if anyone want to see where Database.AllowsCallouts gets mentioned in the documentaiton, they now call it out on the Queuable page: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_queueing_jobs.htm