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
Arvind1Arvind1 

Using actionpoller for commandbutton

Hi All,

 

I have a requirement where the record should be saved 5 seconds after the click of a button.

 

I know that there is an actionpoller function in which I can give the time interval to perform the action.

But I am not getting the syntax how to use actionpoller with commandbutton.

 

Any suggestion on this will be of a great help.

 

Thanks

Arvind

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I reckon you'd want something like:

 

 

<apex:actionFunction name="doSubmit" action="{!doSubmit}"/> <apex:commandButton value="Submit" onclick="setTimeout('doSubmit();', 5000); return false;"/>

 

 

 

 

All Answers

bob_buzzardbob_buzzard

ActionPoller is more for regular periodic updates - e.g. I use this in a monitoring solution to refresh the values every 'n' minutes.

 

It may be possible to do this by having the action method tied to the command button set a value in the controller (e.g. showpoller set to true), then have an outputpanel containing the actionpoller only rendered if showpoller is true.  I haven't tried this though - it feels a bit clunky to me.

 

I'd be inclined to create an actionfunction that ties your save method to a javascript function, and then set the onclick attribute of the commandbutton to something like "setTimeout(your_action_function, 5000)" - that way you are using vanilla javascript and limiting the round trips to the server.

Arvind1Arvind1

Hi Bob,

 

Thanks for the reply.

Could you please give a sample code for this as I am not that much comfortable in javascript.

 

Thanks

Arvind

bob_buzzardbob_buzzard

I reckon you'd want something like:

 

 

<apex:actionFunction name="doSubmit" action="{!doSubmit}"/> <apex:commandButton value="Submit" onclick="setTimeout('doSubmit();', 5000); return false;"/>

 

 

 

 

This was selected as the best answer
Arvind1Arvind1
Thanks Bob, It worked great.