View Data Updates in Real Time with Live Controller (Pilot)

Live controller is a standard Visualforce component that dynamically re-renders a Visualforce page to display changes to data in real time. Visualforce pages automatically re-render the way your Lightning components do with Lightning Data Service. You can use live controller anywhere that you use Visualforce in Lightning Experience. You can have only one live controller per Visualforce page.
Where: This feature is available in Lightning Experience.
Note

Note

We provide live controller to selected customers through a pilot program that requires agreement to specific terms and conditions. To be nominated to participate in the program, contact Salesforce. Pilot programs are subject to change, and we can’t guarantee acceptance. Live controller isn’t generally available unless or until Salesforce announces its general availability in documentation or in press releases or public statements. We can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

When: This pilot feature is available on June 19, 2019.

You can use live controller to listen for updates on a single record with a standard controller or across multiple records with a standard list controller. You can also use it with custom controllers.

How: Include live controller in your Visualforce page with the syntax <apex:liveController />.

Here’s how to use live controller to view updates to a single account record.

<apex:page standardController="Account">
    <apex:liveController/>
    <apex:detail subject="{!account.id}"/>
</apex:page>

First, you define the standard controller. In the second line, you create the live controller, which listens for updates to the standard controller record. Live controller updates the Visualforce page when the account updates.

With custom controllers, use the live controller records attribute to track changes to a record. This example renders a list of account names for the custom controller accountsController. To get all the records associated with the Account object, assign the expression {!accounts} to the records attribute. Then, create a form to hold a table, where you iterate over the list of accounts. An account name in each row is displayed.

<apex:page controller="accountsController" tabstyle="Account">
    <apex:liveController records="{!accounts}"/>
    <apex:form>
        <apex:pageBlockSection >
        <apex:dataList value="{!accounts}" var="acct" type="1">
            <apex:outputText value="{!acct.name}"/>
            </apex:dataList>
        </apex:pageBlockSection>
    </apex:form>
</apex:page>

Live controller provides additional attributes to control the behavior of an update. This example uses the oncomplete attribute to display an alert when an update occurs.

<apex:page standardController="Account">
    <script language="javascript">
        function complete() {
            alert("An update has occurred");
        }
    </script>

    <apex:liveController oncomplete="complete();"/>
    <apex:detail subject="{!account.id}"/>

</apex:page>

Here, a JavaScript function complete() shows an alert message. When you create the live controller, you assign complete() to the oncomplete attribute so that the code runs when live controller detects an update to an account record.