Understanding apex:actionPoller Component in Visualforce

The <apex:actionPoller> component enables your Visualforce page to automatically refresh parts of the page at regular time intervals. It’s useful for displaying real-time data, like status updates, live feed, or job progress.


Key Features

  • Periodically calls an Apex method.
  • Works in the background without user interaction.
  • Uses AJAX for seamless updates.
  • Can rerender specific components.

Syntax

xmlCopyEdit<apex:actionPoller interval="5" action="{!refreshData}" rerender="outputPanel"/>
  • interval: Time in seconds between each call.
  • action: The Apex method to call.
  • rerender: The component to update.

Example: Live Clock

xmlCopyEdit<apex:page controller="PollerController">
    <apex:form>
        <apex:outputPanel id="outputPanel">
            <h3>Current Time: {!currentTime}</h3>
        </apex:outputPanel>

        <apex:actionPoller interval="1" action="{!updateTime}" rerender="outputPanel"/>
    </apex:form>
</apex:page>

Apex Controller:

apexCopyEditpublic class PollerController {
    public String currentTime { get; set; }

    public PollerController() {
        updateTime();
    }

    public void updateTime() {
        currentTime = String.valueOf(System.now());
    }
}

Use Cases

  • Show real-time logs or monitoring data.
  • Display live queues or notifications.
  • Update job processing progress.

Tips

  • Set a reasonable interval to avoid performance issues.
  • Don’t rerender too many components at once.
  • Combine with <apex:outputPanel> to isolate updates.