4

I am building a custom visualforce page to display list of Accounts and wanted to take advantage of the custom Account Controller filter Property to be able to filter accounts on the page. All I get is just 1 value on the ListView e.g 'All', I want to be able to see e.g 'Recently Viewed Accounts','New This Week' etc. I have checked my code but can't find any error. My code is below.I will be glad if someone can help.

        <apex:page standardController="Account" recordSetVar="accounts">
  <apex:form >
    <apex:pageBlock title="Account List" >
        <apex:outputLabel value="View:"/> &nbsp;
        <apex:selectList value="{!filterId}" size="1">
            <apex:selectOptions value="{!listviewoptions}"/>
        </apex:selectList>
        <apex:pageBlockTable value="{!accounts}" var="a">

        <apex:column > <!-- apex:colum is used to provide columns for pageBlockTables -->
            <apex:facet name="header"> <!--  apex:facet is used to provide header and footer names for the columns in the  pageBlockTables -->
                Account Name
            </apex:facet>

            <apex:facet name="footer">
                End of Table
            </apex:facet>

                <apex:outputField value="{!a.Name}"/>
         </apex:column>

        <apex:column >
            <apex:facet name="header">
                Account Phone Number
            </apex:facet>
                <apex:outputField value="{!a.Phone}"/>
        </apex:column>

    </apex:pageBlockTable>

    <apex:commandLink action="{!previous}">Previous</apex:commandLink> <!-- this is used to add the previous page button to the page-->&nbsp;
    <apex:commandLink action="{!next}"> Next</apex:commandLink> <!-- this is used to add next page button to the page-->

    </apex:pageBlock>
</apex:form>

  • @Mohith Shrivastava Thanks for editing my question, any ideas why it is not displaying as expected? – user3722925 Feb 20 '16 at 11:27
  • try 'apex:dataList' tag – Tushar Sharma Feb 20 '16 at 11:32
  • hey @user3722925 when you change your picklist .. data should display based on your list view selected option? – Ratan Paul Feb 20 '16 at 13:06
  • @Ratan my picklist is not giving any option apart from "All", I want all the standard views available in the Standard Controller e.g 'Recently Viewed Accounts','New This Week' etc. The only value I can select on my picklist is 'All', why is this the case? – user3722925 Feb 20 '16 at 14:28
  • 1
    @user3722925 For me it is showing Recently Viewed Accounts .... check my attached image.. – Ratan Paul Feb 20 '16 at 15:05
0

Try adding an extension to see if you are getting any values from the StandardSetController:

public with sharing class AccountListViewExtension
{
    public String selectedFilterId { get; set; }
    public List<SelectOption> filters { get; private set; }

    public AccountListViewExtension(ApexPages.StandardSetController controller)
    {
        filters = controller.getListViewOptions();
        selectedFilterId = controller.getFilterId();

        for (SelectOption filter : filters) system.debug(filter);
    }
}

If the extension finds the filters and you can't get it working without, you can change the markup to:

<apex:selectList value="{!selectedFilterId}">
    <apex:selectOptions value="{!filters}" />
</apex:selectList>

If the Apex above also cannot find any listViewOptions, then you're having a visibility issue. Try running this query and see if you get any results:

SELECT Name, DeveloperName FROM ListView WHERE SObjectType = 'Account'

If both of the above are failing, you can try retrieving just the ListView records you need without sharing.

public with sharing class AccountListViewExtension
{
    public String selectedFilterId { get; set; }
    public List<SelectOption> filters { get; private set; }

    public AccountListViewExtension(ApexPages.StandardSetController controller)
    {
        filters = new ListViewFinder.getListViewOptions();
        selectedFilterId = filters[0].value();
    }

    public without sharing class ListViewFinder
    {
        public List<SelectOption> getListViewOptions()
        {
            List<SelectOption> filters = new List<SelectOption>();
            for (ListView listView : [
                SELECT Name FROM ListView WHERE SObjectType = 'Account'
            ]) filters.add(new SelectOption(listView.Id, listView.Name));
            return filters;
        }
    }
}
| improve this answer | |
  • My apologies that was a mistake.. – user3722925 Mar 9 '16 at 17:55
  • @user3722925 So you tried all of the above recommendations and still were not able to view the List Views? Do you have an Id parameter on the page? – Adrian Larson Mar 9 '16 at 21:11

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.