1

Is there a way to determine if an object supports list view?

I've developed a VF page which shows a list of Objects and based on Object selection it shows list views of that selected object. For some objects like EmailTemplate, Organization etc it throwing system exception "List Controllers not supported for ...."

I'm using below code to fetch list views of Selected Object. However, this code is failing for objects like EmailTemplate, Organization etc

Hence, my question, is there a way to determine if an object supports list view?

String baseQuery = 'Select ID  FROM ' + SelectObject + ' Limit 1'; 
objSetController = new ApexPages.StandardSetController(Database.getQueryLocator(baseQuery));
List < SelectOption > options = objSetController.getListViewOptions();
2

I researched something similar recently and stumbled upon across this standard object ListView

The ListView record tells you if the ListView is SOQL compatible,(which you are trying to do)

So you go by

ListView lv = [SELECT IsSoqlCompatible FROM ListView WHERE SobjectType=:SelectObject LIMIT 1];
if(lv.IsSoqlCompatible){
    String baseQuery = 'Select ID  FROM ' + SelectObject + ' Limit 1'; 
    objSetController = new ApexPages.StandardSetController(Database.getQueryLocator(baseQuery));
    List < SelectOption > options = objSetController.getListViewOptions();
}else{
    //ListView SOQL not supported handle here

}
1

I think the approach to fetch the listviews through setcontroller is kind of problematic here. Per this doc, only specific objects are supported. There is this ListView object which gives the list of the listviews in the system. When I queried for EmailTemplate, it did not throw any error but simply returned 0 values.

SELECT CreatedById,CreatedDate,DeveloperName,Id,IsSoqlCompatible,LastModifiedById,LastModifiedDate,LastReferencedDate,LastViewedDate,Name,NamespacePrefix,SobjectType,SystemModstamp FROM ListView WHERE sObjectType='EmailTemplate'

To get all the supported objects: The sObjectType field in the ListView is picklist field and you can get all the values of that picklist field using PicklistValueInfo.

  • 1
    Thanks @Shailesh. I agree that this seems to be a better way of finding a list of objects that support list views. Thanks! – Chirag Mehta Jan 17 at 12:30
  • You are welcome @ChiragMehta! – Shailesh Patil Jan 19 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.