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

Disable a button until an @future method is finished

I am writing a VF page which will be used to reassign a user's opportunities to a set of other users in a Round Robin fashion. This part is working. 


However, I was told to make this reassignment asynchronous (@future) and disable the button on the VF page until the process is finished so the user cannot keep clicking the button on the VF page.  Is this possible to do? How can I track when the @future process is finished?




Chris DaviesChris Davies



I assume that you are making a callout (with @future = true)


Why don't you create a flag/checkbox on the object with default value = true. At the end of the initial callout you use workflow field update to set the flag to false.


Your button <apex: button action="{Your At Future Method}" rendered="{!NOT(Flag)}">


This button will only ever appear when the method is not in progress.


Actually after thinking about it more, I think I am going to have my page spawn a batched apex process. Is there anyway for me to tell the VF page when it's finished? I think maybe a better way is just spawn the batched apex and redirect the user to a page that says something like "The bulk transfer has been submitted." instead of worrying about sending information back to the VF page.

Dirk GronertDirk Gronert

You can use the new Streaming API to achieve your requirement .... or !


In the first link you will find an example! 


I think you have to combine the logic of an additional field (checkbox) and the streaming API!


Good luck!