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
AutobatAutobat 

Visualforce Controller Constructor Unable to Fire @future?

Hey Guys,

So I have created a heap of code that works perfectly if the entry point to my class is executed from an SControl using the old sforce.apex.execute(…) method and a web service.  Now the web service that fires basically tees up an Argument and Return object and then fires the entry point in one of my campaign automation classes.

Now here comes the interesting bit, and by interesting I swore very loudly!

If I move that web service code into the constructor of my Visualforce controller all of the code runs perfectly apart from none of the future methods are queued up and therefore not run……..  The code (confirmed by System Debug messages) just jumps over the call to the @future, the two log files look near identical with the only difference being what process inits everything.

Any ideas?  I really don’t want to execute this code from an SControl.
JimRaeJimRae
The documentation indicates that it must be a statuc method, and can only return a void type, are you complying with that? There are some other stipulations listed as well .
dchasmandchasman
This is a case where we missed adding a runtime error (already fixed in the next release) that should indicate that you can only invoke @future methods via action methods - same rules as DML - move the call to an action method and you should be good to go. If you need this to run when the page is retrieved (basically right after the ctor runs) you can wire up <apex:page action="{!yourActionHere}"> to achieve the same result but in a way that the transactional semantics can be satisfied.
AutobatAutobat
Aha, that would explain the lack of error and future processing!

Many thanks Doug