function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NitishNitish 

Why future methods should be Static and Void in apex? Why can't we declare it non-static and with a return type?

Best Answer chosen by Nitish
GauravGargGauravGarg

Nitish,

Yes, you are correct since Future methods can be accessed from any class and not depend on any class instance it is declared as Static, also Static keyword make it as utility method rather than normal class method. 

why Void?
Future method runs on it own thread, so it cannot return any values to previous instance. 

Hope this make sense. 

Thanks,

Gaurav

All Answers

Ashish KumarAshish Kumar
Hi Nitish,

You may find this reference useful.

https://www.forcetalks.com/salesforce-topic/why-future-method-is-void-and-static-in-salesforce/

hope this helps.

Regards,
NitishNitish
Hi Ashish,

Thanks for your quick response.
"Future method by definition is static so that variables with this method is associated to the class and not the instance and you can access them without instantiating the class."

Is this the only reason to declare future method as static?

Regards,
GauravGargGauravGarg

Nitish,

Yes, you are correct since Future methods can be accessed from any class and not depend on any class instance it is declared as Static, also Static keyword make it as utility method rather than normal class method. 

why Void?
Future method runs on it own thread, so it cannot return any values to previous instance. 

Hope this make sense. 

Thanks,

Gaurav

This was selected as the best answer
NitishNitish
Thanks Gaurav it helps me to understand the concept.
Regards