Standard Controllers in Visualforce

A common VisualForce interview question is –
How do you differentiate a StandardController, a StandardSetController, a StandardListControlller, and Controller with Extensions, why do we use them, when do we use them and what are the limitations? Let’s look into the same below:

So, there are 3 primary type of controllers:

  1. Standard Controller:
    StandardController is used when we want to bind an object with our VisualForce page using out of the box Salesforce provided controller, which supports both standard and custom objects with basic bindable properties.
    <apex:page standardController=”Account”> represents a standard object standard controller.
    <apex:page standardController=”Financial__c”> represents a standard controller for a custom object.
    To utilize this VisualForce Page, we need to pass the id (recordId) parameter to fetch the values from the record.

  2. StandardListController:
    If we want to work with multiple records instead of one, we need to define the recordSetVar attribute along with the standard controller attribute which would look something like this:
    <apex:page standardController=”Account” recordSetVar=”accountList”>
    StandardSetController provides us with easy to access standard actions which can be utilized for easy implementations instead of going custom.

  3. Controller Extensions:
    To add custom functionality which is not limited to the object used in StandardController or out of the box available functions, we need to add controller extensions which can help us with the same.
    Here, we can access standard functionality using our StandardController abilities and add features/functionalities needed for the VF Page using the extension controller.
<apex:page standardController="Account" extensions="ExtensionController">

If you have more knowledge on this piece, please share the same below, it would be helpful.

« »