You need to sign in to do that
Don't have an account?

Help for few questions
Hello, I have a doubt on this question:
which code block returns the listview of an Account object using the following debug statement?
system.debug(controller.getListViewOptions());
A. ApexPages.StandardSetController controller = new Apexpages.StandardSetController([SELECT id FROM Account LIMIT 1]);
B. ApexPages.StandardController controller = new ApexPages.StandardController(Database.getQueryLocator('select id from account limit 1')).
C. ApexPages.StandardController controller = new ApexPages.StandardController([SELECT id FROM Account LIMIT 1]);
D. ApexPages.StandardSetController controller = new ApexPages.StandardSetController(database.getQueryLocator('select id from Account Limit 1'))
The correct answer seems to be D, but I didn0t understand why D and not A (trying by dev console, both worked): can anyone help me, please?
which code block returns the listview of an Account object using the following debug statement?
system.debug(controller.getListViewOptions());
A. ApexPages.StandardSetController controller = new Apexpages.StandardSetController([SELECT id FROM Account LIMIT 1]);
B. ApexPages.StandardController controller = new ApexPages.StandardController(Database.getQueryLocator('select id from account limit 1')).
C. ApexPages.StandardController controller = new ApexPages.StandardController([SELECT id FROM Account LIMIT 1]);
D. ApexPages.StandardSetController controller = new ApexPages.StandardSetController(database.getQueryLocator('select id from Account Limit 1'))
The correct answer seems to be D, but I didn0t understand why D and not A (trying by dev console, both worked): can anyone help me, please?
A and D should work as both constructors are correct.
[SELECT id FROM Account LIMIT 1] is ambiguous.
if ([SELECT Name FROM Account LIMIT 1] instanceof List<account>) {system.debug('test list ok');} // OK
if ([SELECT Name FROM Account LIMIT 1] instanceof account) {system.debug('test account ok');} // ERROR
List<account> accountList = [SELECT Name FROM Account LIMIT 1];
system.debug('accountList name : ' + accountList[0].name);
... but this also works (limit 1 is ambiguous):
account acc = [SELECT Name FROM Account LIMIT 1];
system.debug('acc name : ' + acc.name); // OK
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_ApexPages_StandardSetController_constructors.htm
Regards
List<account> accountList = [SELECT Name FROM Account LIMIT 20];
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(accountList);
or
List<account> accountList = [SELECT Name FROM Account LIMIT 1];
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(accountList);
or
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController([SELECT Name FROM Account LIMIT 1]);
The all thing works as long as LIMIT 1 is an instance of List<Account> (check with instanceof)
Perhaps a very bad practice (ambiguous) but that works with LIMIT 1.
Regards