Newer Version Available
Subscribe to Multiple Records
Standard List Controller
Live controller automatically tracks changes to records used by the standard list controller with the recordSetVar attribute.
This example shows how to update a list of opportunity records in a form. When any opportunity name or amount updates, live controller refreshes the Visualforce page.
1<apex:page standardController="Opportunity" recordSetVar="opptys">
2 <apex:liveController reRender="thePageBlock"/>
3 <apex:form >
4 <apex:pageBlock id="thePageBlock">
5 <apex:pageBlockButtons >
6 <apex:commandButton action="{!quicksave}" value="Quick Save"/>
7 <apex:commandButton action="{!previous}" value="Previous"/>
8 <apex:commandButton action="{!next}" value="Next"/>
9 </apex:pageBlockButtons>
10 <apex:pageBlockTable value="{! opptys}" var="o">
11 <apex:column value="{!o.name}"/>
12 <apex:column headerValue="Amount">
13 <apex:inputField value="{!o.amount}"/>
14 </apex:column>
15 </apex:pageBlockTable>
16 </apex:pageBlock>
17 </apex:form>
18</apex:page>Setting the recordSetVar attribute indicates that the Visualforce page uses the standard list controller. The value of opptys sets the variable name in the record collection. We use it to access data in the collection.
Control Active Elements with the reRender Attribute
You can use the reRender attribute to control how user input elements respond to interaction. The syntax is reRender="{elementId}". After a user interaction takes place, this attribute refreshes only the component it is assigned to. When used with live controller, it also pauses updates to data when an element is active, like when a user types text in a form field. On Visualforce pages that include live controller, only use reRender on <apex:liveController>. Do not use it on other components.
Custom Controller with records Attribute
Use the records attribute to track changes to multiple records in a custom controller. If you don’t include this attribute, Visualforce displays updates to records only tracked by the standard controller. Updates to other records don’t load on the page.
This example renders a list of information related to donations for the custom controller DonationsController. To get all the records associated with the Donation_Site__c object, assign the expression {! donationLocations} to the records attribute. Then, create a form to hold a table, where we iterate over the list of donation locations. Each row has two columns that display the name and address.
In the DonationsController class, the getDonationLocations() method loads a list of donation locations.
1<apex:page controller="DonationsController">
2 <apex:liveController records="{! donationLocations}" />
3 <apex:pageBlock title="All sites">
4 <apex:pageBlockTable value="{! donationLocations}" var="item">
5 <apex:column value="{!item.name}"/>
6 <apex:column value="{!item.Address__c}"/>
7 </apex:pageBlockTable>
8 </apex:pageBlock>
9</apex:page>1public with sharing class DonationsController {
2
3 public List<Donation_Site__c> getDonationLocations() {
4 List<Donation_Site__c> sites = [SELECT Id, Name, Address__c
5 FROM Donation_Site__c];
6 return sites;
7 }
8}Limitations
When you use live controller to subscribe to changes in multiple records, your page refreshes when any record updates. You can subscribe to a maximum of 50 records per Visualforce page and five objects. For example, you can subscribe to Accounts, Opportunities, and three custom objects on a single page.