function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Brianne Wilson 4Brianne Wilson 4 

Custom Visualforce Tab - Filter All ListViews in getListViewOptions() to only a select few

Summary of Requirements: 
- The client uses two separate record types for the standard Order object. 
- Cannot split this into two separate objects
- Have built a custom visualforce tab with the purpose of displaying only the list views for Orders pertaining to that record type
- I've been able to make the list view dynamic, where the component displaying the list view searches for the list view label that matches the picklist string value (ex. String Value = "List View A", the list view changes to List View A).

Problem:
- I have only been able to get it to work by hardcoding the labels of the desired list view into the controller. I'd like to make this dynamic as well, so that we don't have to maintain it. Should the client create list views down the road, I want those to appear on the tab as well.

Need: Filter List Views available to only those list views with the word "O2".

I'm assuming it's somehow using getListViewOptions(), but I couldn't figure out how to filter that. When I tried to use that, it by default returns all list views. So somehow setting a variable for the results, turning them to a string, and seeing if it contains the right word....and then returning those options to the list. But I couldn't get any of my code to work. If anyone can help it would be much appreciated!


Visualforce Page:
<apex:pageBlockSection >
            <apex:form >
                <apex:outputLabel style="font-weight: bold; margin-right: 10px;">Select View: </apex:outputLabel>
                <apex:selectList id="selectView" required="true" title="PickList1" size="1" value="{!propPickValSelected}" style="width: 225px;" label="Select View:">
                    <apex:selectOptions value="{!PickLstValue}" />
                    <apex:actionSupport event="onchange"/>
                </apex:selectList> 
            </apex:form>
        </apex:pageBlockSection>

Controller Snippet, which sets the values in the picklist:
Public string propPickValSelected { get; set; }
    
    public List<SelectOption> getPickLstValue()
    {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption(' ','------------- SELECT -------------'));
        options.add(new SelectOption('O2 - All','O2 - All'));
        options.add(new SelectOption('O2 - New','O2 - New'));
        options.add(new SelectOption('O2 - Cancelled','O2 - Cancelled'));
        options.add(new SelectOption('O2 - Closed','O2 - Closed'));
        return options;
    }
    
    public String getpropPickValSelected() {
        return propPickValSelected;
    }
    
    public void setpropPickValSelected(String propPickValSelected) {
        this.propPickValSelected = propPickValSelected;
    }

Note: I had at one point tried using this http://www.jitendrazaa.com/blog/salesforce/listview-filter-in-apex-with-paging-and-navigation/ and updating it to filter out, but couldn't get it to work either. Just figured I'd point you here too in case this helped.