I have a page where I am trying to show which ListViews a Project is in. I can get the data I want in the Developer Console by querying ListView. However, when I try to import the following query to my code I get the following exception: "Save error: sObject type 'ListView' is not supported." Query:
SELECT Id, Name FROM ListView WHERE SObjectType = 'Project__c'
As a workaround, I am trying to instantiate an Apex:StandardSetController for Project__c and call getListViewOptions(). Notice I am not calling getListViewOptions on my ApexPages.StandardController. The relevant bit that is not working:
public MyExtension(ApexPages.StandardController notUsed)
{
debugListViews(); // yields bogus results
}
public MyExtension(ApexPages.StandardSetController notUsed)
{
debugListViews(); // yields valid results
}
private void debugListViews()
{
ApexPages.StandardSetController controller = new ApexPages.StandardSetController([
SELECT Id FROM Project__c LIMIT 1
]);
for (SelectOption option : controller.getListViewOptions())
{
system.debug(option);
}
}
This code works perfectly in Execute Anonymous. I see a list of SelectOption each of which has a valid Name/Id combination. However, when I run this code in my extension's constructor that takes in an ApexPages.StandardController, I get only one SelectOption that is clearly bogus. The Name is "All" and the Id is "000000000000000AAA". Note: the key prefix for ListView is "00B."
To add to the mystery, this code also works as expected in my extension constructor that takes in an ApexPages.StandardSetController.
This seems like it is a Salesforce bug, but I am not allowed to submit a Development Case for this org. Has anyone run into this before and found a workaround?