Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Please provide some idea on the below queries,

  1. How many ways we can get an id for an enhanced list view other than from a standard view?.
  2. If we need to create an enhanced list view for a custom object with record condition which involves a field from parent Object, then how to create a view for this since the standard view could not have a parent field to be included in the filter condition.
share|improve this question
up vote 6 down vote accepted

Not quite sure I've understood you correctly, but for your first requirement you can actually retrieve a list view ID in Apex by using a StandardSetController for the object in question:

Database.QueryLocator ql = Database.getQueryLocator('select id from Custom__c');
ApexPages.StandardSetController setController = new ApexPages.StandardSetController(ql);
System.SelectOption[] listViews = setController.getListViewOptions();
String listViewID = null;
for(System.SelectOption listView : listViews)
    if(listView.getLabel() == 'Custom List View Name of Interest') 
        listViewID = listView.getValue();

For your second requirement, create a formula on the child object that pulls down the parent field to the child.

share|improve this answer
Thanks Phil for your time. But Is there an alternative approach available to create a custom view other than creating it using standard "Create new view" options under the tabs?. Which would also generate the id of the enhanced list? I meant the same "Id" would be generated if possible using the above method as in the case if the view is created using a standard "Create New View" option under the particular object UI (tab). – vedakri May 13 '14 at 10:22
Ah, ok so you wish to create a new List View from within your code? I think in that case then you will have to use the metadata API. Look at the work that @AndrewFawcett has done I'm afraid its not something I have tried personally. – Phil Hawthorn May 13 '14 at 10:34

1 - Metadata API or you can store the Id in a Custom Settings or Labels. To get the Id of a List View you can find it in the URL rendered when you select it

2 - You can achieve this by creating a formula field to get the parent object field and you can add it in the list view as a condition with no problem

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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