Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

What is the difference between list controllers and set controllers?

share|improve this question

1 Answer 1

The two controllers that are available to you are:

  • StandardController
  • StandardSetController

StandardController

From the docs: A Visualforce controller is a set of instructions that specify what happens when a user interacts with the components specified in associated Visualforce markup, such as when a user clicks a button or link. Controllers also provide access to the data that should be displayed in a page, and can modify component behavior.

You can find more information here, but basically a StandardController is for ONE record, i.e. if you'd like to create a new Visualforce page for a single record, you'd use a Standard Controller in your Apex. For example:

public with sharing class MyController {
    private ApexPages.StandardController controller;

    public MyController(ApexPages.StandardController controller) {
        this.controller = controller;
    }   
    // maybe this gets called from a button within your VF page
    public void doSomethingWithSingleRecord() {
        SObject record = controller.getRecord();

        record.put('Status__c', true);
        update record;
    }

}

StandardSetController

From the docs: Standard list controllers allow you to create Visualforce pages that can display or act on a set of records. Examples of existing Salesforce pages that work with a set of records include list pages, related lists, and mass action pages.

You can find more information here, but basically Set (list) controllers are for MULTIPLE (or a list of) records, i.e. if you'd like to create a new Visualforce page for a List of records (or even from a selection of records on a List view), you'd use a Standard Set Controller in your Apex. For example:

public with sharing class MyController {
    private ApexPages.StandardSetController setController;

    public MyController(ApexPages.StandardSetController setController) {
        this.setController = controller;
    }
    //maybe this gets called from a button on your list view
    public void doSomethingWithMultipleRecords() {
        List<SObject> records = setController.getSelected();

        for(SObject record : records) {
            record.put('Status__c', true);
        }

        update records;
    }
}
share|improve this answer
    
Thanks!It will help me –  AnkushSalesforce Aug 31 at 11:47
    
Happy to help, let me know if anything is not clear! –  executeanon Aug 31 at 13:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.