Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, 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.

setSelected(selectedRecords)

Set the selected records to the records specified in the selectedRecords argument.

Signature

public Void setSelected(sObject[] selectedRecords)

Parameters

  • selectedRecords: Type: sObject[]

Return Value

Type: Void

Usage

Use the setSelected() method in your Apex controller or controller extension to manually set the records displayed on a Visualforce page. The setSelected() method overwrites any previously selected records with the records specified in the selectedRecords argument.

Example

AccountNamePage shows a table of account names. MyControllerExtension’s constructor contains a SOQL query that returns a list of accounts. This list is passed into setSelected() so that the account records in the list are selected and displayed in the table.

1<!-- AccountNamePage.page -->
2<apex:page standardController="Account" recordSetVar="accounts" extensions="MyControllerExtension">
3    <apex:pageBlock>
4        <apex:pageBlockTable value="{!accounts}" var="acc">
5            <apex:column value="{!acc.name}"/>
6        </apex:pageBlockTable>
7    </apex:pageBlock>
8</apex:page>
9
10
11// MyControllerExtension.cls
12public with sharing class MyControllerExtension {
13    private ApexPages.StandardSetController setController;
14
15    public MyControllerExtension(ApexPages.StandardSetController setController) {
16        this.setController = setController;
17        
18        Account [] records = [SELECT Id, Name FROM Account LIMIT 30];
19        setController.setSelected(records);
20    }
21}