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
Chris987654321Chris987654321 

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?

 

Thanks,

Chris

Chris DaviesChris Davies

Chris,

 

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.

Chris987654321Chris987654321

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 ....  http://wiki.developerforce.com/page/Getting_Started_with_the_Force.com_Streaming_API or http://wiki.developerforce.com/page/Streaming_API !

 

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!

 

Cheers,

 

--dirk