6

I don't understand the difference between:

@future (callout= true)

and

@future (callout= false)

I have read the documentation, but I don't understand where to use one or the other.

3 Answers 3

11

If you want to call third party system or any http call outside of salesforce system you need to set callout=true in the future method. If you set it to false it means the method is not making any http callout.

By default its false to there is no need to mention callout= false

2
  • And are there any reason to do it? Why do you have to specify it? Apr 13, 2017 at 14:43
  • so like i said if you want to call any external system or any third party services like google map or autocomplete you make a http call to the third party system. if you dont say callout=true it means the future method cannot call the external system. by explicitly using this annotation you are basically saying this method is allowed to make http callouts and will do a callout to implement some functionality
    – RedDevil
    Apr 13, 2017 at 14:47
8

The document you linked and the annotation itself both seem quite clear:

To allow callouts in a future method, specify (callout=true). The default is (callout=false), which prevents a method from making callouts.

The following snippet shows how to specify that a method executes a callout:

@future (callout=true)
public static void doCalloutFromFuture() {
    //Add code to perform callout
}

That's just how the language was designed. By default future methods cannot make callouts. It's pretty similar to other asynchronous jobs in forcing you to specify when they interact with external systems.

Using Callouts in Batch Apex

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{
}

Callouts include HTTP requests and methods defined with the webService keyword.

As a consequence of the above, you can determine at compile time (just based on the SymbolTable, for example) which asynchronous methods are strictly internal, versus those that can interact with other systems.

1
  • I have already chosen another answer as correct, but yours are also good, thanks. Apr 13, 2017 at 15:17
-1

Its quite simple, where you want to callout third party when resources available, annotate the future method as 'callout= true'. If you want perform some other asynch operations/other future method operations like mixed DML then no need to annotate callout as by default its false

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .