1

Like with 'without sharing' and 'with sharing' for class, 'without sharing' has clear use in case you want to explicitly turn off sharing rule enforcement when a class acquires sharing rules when it is called from another class that is declared using 'with sharing'.

So, whats the explicit use of 'callout=false' in future method ?

4

Generally speaking, in programming it's better to be explicit than implicit because it reduces the chance for other people (including yourself 6 months from now) to be confused about a behavior. Sure, you and I know that callouts are not allowed from future methods by default, but what about a new developer? Sure, they could read the documentation, but there's a lot of documentation. It takes time to learn the idiosyncrasies of Salesforce; and I'm a proponent of not making things harder than they need to be.

Other than that, there is no use. Giving an @future method (callouts=false) doesn't accomplish anything.

Why does it exist if it doesn't do anything then?
Because writing compilers is hard, and if you're going to give something the ability to be set to true (i.e. a boolean), you're pretty much forced to allow that value to be set to false as well unless you want to spend even more time adding another primitive to your formal type system.

1

The compiler uses the older-style Annotation system from Java (later versions allow parameter values without keys). In other words, callouts=false exists only because callouts=true exists, and both must be honored because of how the @future annotation is written in the source code. It doesn't matter that one of those values are default, the compiler must allow both of them, because that's how the run-time works.

There's no practical purpose of writing callouts=false, unless you really want to be explicit that there are no callouts. However, in professional code, you'd rarely, if ever, see such an explicit statement, because it is already the default value. Anyone writing callouts=false would probably be seen by more experienced developers to be a novice, because experienced developers already know the default is false.

It should also be noted that with sharing and without sharing is not a Boolean value; the default is "inherit" mode, which means the current sharing state doesn't change from whatever it's current set to. This is actually a performance benefit, as there is a material cost (CPU time) to specifying with sharing or without sharing.

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.