Action poller is acts as a timer in visual force page. A timer that sends an AJAX request to the Salesforce server according to a time interval that you specified.
The time interval between AJAX update requests is always be in seconds.
This timer value must be 5 seconds or greater than 5, and if it not specified, then defaults to 60 seconds.
In this article, I will demonstrate how to use <apex:actionpoller> in visual force page.
Create Visualforce Page -->
Create Apex Controller: -->
Note that if an <apex:actionPoller> is ever re-rendered as the result of another action, then this tag resets itself. An <apex:actionPoller> must be within the region where it acts upon.
For example, to use an <apex:actionPoller> tag with an <apex:actionRegion> tag, the <apex:actionPoller> tag must be within the <apex:actionRegion> tag.
Check below point while using <apex:actionPoller>
The time interval between AJAX update requests is always be in seconds.
This timer value must be 5 seconds or greater than 5, and if it not specified, then defaults to 60 seconds.
In this article, I will demonstrate how to use <apex:actionpoller> in visual force page.
Create Visualforce Page -->
<apex:page controller="exampleCon">
<apex:form>
<apex:outputText value="This counter is changing, check this: {!count}" id="counter"/>
<apex:actionPoller action="{!incrementCounter}" reRender="counter" interval="15"/>
</apex:form>
</apex:page>
Create Apex Controller: -->
public class exampleCon {
Integer count = 0;
public PageReference incrementCounter() {
count++;
return null;
}
public Integer getCount() {
return count;
}
}
Note that if an <apex:actionPoller> is ever re-rendered as the result of another action, then this tag resets itself. An <apex:actionPoller> must be within the region where it acts upon.
For example, to use an <apex:actionPoller> tag with an <apex:actionRegion> tag, the <apex:actionPoller> tag must be within the <apex:actionRegion> tag.
Check below point while using <apex:actionPoller>
- Action methods used by <apex:actionPoller> tag should be lightweight. It's a best practice to avoid performing error whcih are occured in DML, external service calls, and other resource-intensive operations in action methods called by an <apex:actionPoller> tag .
- <apex:actionPoller> tag refreshes the connection regularly, which keeping login sessions alive. A page with <apex:actionPoller> tag on visualforce won't time out due to inactivity.
- If an <apex:actionPoller> tag is ever re-rendered as the result of another action, then this tag resets itself.
- Time out can also be specified as an attribute in actionpoller tag. Once the time out point is reached it stops making AJAX callout to the Salesforce server and no more controller method is called.
Below are the attributes supported by actionpoller tag:
Attribute
|
Description
|
action
|
The action () invoked by the timer for a periodic AJAX update request from the page. Use the merge field syntax to reference the action method. For example, action="{!incrementCounter}" references the incrementCounter() method in the controller. If no an action is specified, then the page simply refreshes.
|
enabled
|
This is a Boolean value that indicates whether the poller is active or not. If not specified, then this value defaults to true.
|
id
|
An identifier that allows the one component to be referenced by other components in the page.
|
interval
|
This is the time interval between 2 AJAX update requests, which is in seconds. interval value must be 5 seconds or greater than that, and if this value is not specified, then by defaults Salesforce take is as 60 seconds. Keep in mind that the interval is only the amount of time between the update requests. Once an update request is sent to the server, it enters a server queue and can take additional time to process and display to the client.
|
oncomplete
|
The JavaScript function invoked when the result of an AJAX update request completes on the client.
|
onsubmit
|
The JavaScript function invoked before an AJAX update request has been sent to the server.
|
rendered
|
A Boolean value that indicates whether the component is rendered on the page or not. If this not specified, then this value defaults to true.
|
reRender
|
The ID of one or more components that are redrawn when the result of an AJAX update request returns from a server to the client. This value can be a single ID or can be a comma-separated list of IDs, or a merge field expression for a list or collection of IDs.
|
status
|
The ID of a related to the component that displays the status of an AJAX update request.
|
timeout
|
The amount of time specified in milliseconds before an AJAX update request should time out.
|
Enjoy! If you have any questions, comments etc. please feel free to let me know. As always, please feel free to get in touch me as I would be more than happy to assist you with any of your Salesforce development needs.