salesforce
  1. salesforce-apex-actionpoller-component

apex:actionPoller Component

The apex:actionPoller component is a Visualforce component in Salesforce that enables polling of the server at specified intervals. It allows you to execute server-side actions automatically, based on a specified time interval.

Syntax

The syntax for apex:actionPoller is as follows:

<apex:actionPoller action="{!controllerMethod}" interval="number" reRender="componentId"/>

Example

Consider the following code:

<apex:page controller="MyController">
  <apex:form >
    <apex:outputPanel id="countPanel">{!count}</apex:outputPanel>
    <apex:actionPoller action="{!incrementCount}" interval="10" reRender="countPanel"/>
  </apex:form>
</apex:page>

In the above example, the apex:actionPoller component is used to increment the value of a counter by calling the controller method incrementCount() every 10 seconds. The updated count is then displayed in the output panel with id countPanel.

Output

The above code will output a page with an output panel that displays the count value. The count value will be incremented every 10 seconds.

Explanation

The action attribute of the apex:actionPoller component specifies the server-side method that needs to be called to perform some action. In the above example, the incrementCount() method in the MyController controller is called every 10 seconds.

The interval attribute specifies the number of milliseconds the poller waits before making a request to the server. In the above example, a value of 10,000 milliseconds (10 seconds) is specified.

The reRender attribute specifies the component or components that need to be updated after the server-side method is executed. In the above example, the output panel with id countPanel will be updated after every server call.

Use

The apex:actionPoller component can be used in scenarios where you want to execute server-side actions automatically. It is particularly useful when you need to keep a part of the page updated with new information without refreshing the entire page.

Important Points

  • The apex:actionPoller component has a limit of 100 maximum polling intervals or approximately 16.5 minutes on a single page.
  • The actionPoller is not supported in Lightning Experience or Salesforce1 mobile app.
  • The interval attribute must be a multiple of 1000 (milliseconds).
  • The action attribute must point to a valid server-side method in the controller.

Summary

The apex:actionPoller component is a Visualforce component in Salesforce that enables polling of the server at specified intervals. It allows you to execute server-side actions automatically, based on a specified time interval. The component can be used in scenarios where you want to keep a part of the page updated with new information without refreshing the entire page. It is important to note that the apex:actionPoller component has limitations and is not supported in Lightning Experience or Salesforce1 mobile app.

Published on: