3

I have read documents for StandardSetController, but I don't understand what it is or why to use it.

2 Answers 2

14

ApexPages.StandardController (documentation) encapsulates just a single Sobject (e.g. Account, Opportunity).

ApexPages.StandardSetController (documentation) 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.

For example in test class when we initialize

ApexPages.StandardController

Account objAccount = [SELECT Name FROM Account LIMIT 1];
ApexPages.StandardController standctrl = new ApexPages.StandardController(objAccount ); 

ApexPages.StandardSetController

List<account> accountList = [SELECT Name FROM Account LIMIT 20];
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(accountList); 
2
  • suppose in ApexPages.StandardController i will change limit 1 to 20 then whats type of effects change. Account objAccount = [SELECT Name FROM Account LIMIT 20]; ApexPages.StandardController standctrl = new ApexPages.StandardController(objAccount ); Mar 1, 2016 at 6:52
  • 1
    @VipinIndora first your query will return list so you need to assign to List<Account> lstAccount and in new ApexPages.StandardController(lstAccount[0]); .. You need pass single record.. Beacuse if you check the documentation StandardController accept only one record..
    – Ratan Paul
    Mar 1, 2016 at 6:54
1

It is also important to note that

The maximum record limit for StandardSetController is 10,000 records. Instantiating StandardSetController using a query locator returning more than 10,000 records causes a LimitException to be thrown. However, instantiating StandardSetController with a list of more than 10,000 records doesn’t throw an exception, and instead truncates the records to the limit.

so use the query locator instantiation to ensure you don't have unexpected truncation occurring.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .