I have read documents for StandardSetController
, but I don't understand what it is or why to use it.
2 Answers
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);
-
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 innew ApexPages.StandardController(lstAccount[0]);
.. You need pass single record.. Beacuse if you check the documentationStandardController
accept only one record.. Mar 1, 2016 at 6:54
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.