function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sharankumar DesaiSharankumar Desai 

Custom Controller Vs Custom List Controller

Hi Folks,

I am bit confused between Custom Controller and Custom List Controller difference.

The reason being ,In Cunstomer controller i can create a method to return list of accounts which i can use in Visualforce page then what is the use case for me to opt Custom List controller (account).?

What is that i can do with Custom List controller which cannot be achieved with Custom Controller.
Amit Chaudhary 8Amit Chaudhary 8
Building a Custom List Controller
1) https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_custom_list_controller.htm
A custom list controller is similar to a standard list controller. Custom list controllers can implement Apex logic that you define to show or act on a set of records
For example you can create the following custom list controller based on a SOQL query
public class opportunityList2Con {
    // ApexPages.StandardSetController must be instantiated
    // for standard list controllers
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [SELECT Name, CloseDate FROM Opportunity]));
            }
            return setCon;
        }
        set;
    }

    // Initialize setCon and return a list of records
    public List<Opportunity> getOpportunities() {
        return (List<Opportunity>) setCon.getRecords();
    }
}

ApexPages.StandardController (documentation (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_pages_standardcontroller.htm)) encapsulates just a single Sobject (e.g. Account, Opportunity).


ApexPages.StandardSetController (documentation (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_pages_standardsetcontroller.htm)) contains a list of records (one or more), and has additional functions to facilitate pagination (moving between pages) and updating a number of records at once.

We can use Standard set controllers provided by salesforce to implement pagination in visualforce. It is very easy to implement pagination using standard set controller. We can easily navigate through pages, move directly to first, last page or to next or previous pages using standard set controller. We can also decide how many records should be displayed in every page. We need to instantiate the StandardSetController and use the standard methods provided by salesforce to leverage the pagination functionality.
1) http://www.sfdcpoint.com/salesforce/pagination-using-standard-set-controller-salesforce/

NOTE:-
1) If you want to perform mass delete with checkbox then i will work
https://www.sundoginteractive.com/blog/a-recipe-for-mass-deleting-salesforce
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_massupdate.htm

Let us know if this will help you