3

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.
7

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();
    }
}    
System.debug(listViewID);

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

| 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 github.com/financialforcedev/apex-mdapi. I'm afraid its not something I have tried personally. – Phil Hawthorn May 13 '14 at 10:34
0

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 ...force.com/a02?fcf=yourListViewId

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

| improve this answer | |

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.