2

I have a combination of an Apex Class, an Apex Controller, a Visualforce Page and a Visualforce component that when put together, are suppose to show a drop down of Contact list views sorted Alphabetically and display in a page list for users to jump several pages of records at a time. However, when someone selects a List View from the drop-down menu and selects "Load List View", it returns nothing, as shown in the photo below (Photo 1). We have output text that we created in the page component that reads "Could not find requested ListView: '{!listName}'. Please contact your administrator." (Photo 2) Can anyone help see where the issue could be?

Visualforce Page

<apex:page standardController="Contact" extensions="NitishContactListViewClass">

<apex:pageBlock > <!-- formatting for the page -->

<apex:form >

<apex:actionStatus id="ajaxStatus" startText="Loading..."  stopText=""/>

    <apex:selectList value="{!conFilterName}" size="1" id="filterMenu">
        <apex:selectOptions value="{!listViewNames}" />
        <!-- <apex:actionSupport event="onchange" action="{!resetFilter}" rerender="contactENlistview" status="ajaxStatus"/>-->
    </apex:selectList> 

    <apex:commandButton action="{!save}" value="Load List View" id="loadListView"/>
    <!--Mass Delete Button-->
    <!--Mass Update Owner Button-->
    <!--Create new list view button-->

</apex:form>

</apex:pageBlock> <!-- /formatting for the page -->
<apex:pageblock ><!-- formatting for the page -->
<apex:outputPanel id="contactENlistview" rendered="{!conFilterName != null}">

    <c:ContactListViewComponent listViewName="{!conFilterName}"  />

</apex:outputPanel>
</apex:pageblock> <!-- /formatting for the page -->
</apex:page>

Component

<apex:component controller="NitishContactListViewController">
  <apex:attribute name="listViewName" type="String" required="true" 
    description="The name of the listview." assignTo="{!listName}"/>

  <apex:enhancedList height="5200" rowsPerPage="200" id="ContactList"
    listId="{!listId}" rendered="{!listId != null}" />

  <apex:outputText rendered="{!listId == null}" value="Could not find requested ListView: '{!listName}'. Please contact your administrator."/>

</apex:component>

Apex Controller

public class NitishContactListViewController {
  public String listName {
    get;
    set {
        listName = value;
        String qry = 'SELECT Name FROM Contact LIMIT 1';
        ApexPages.StandardSetController ssc = 
            new ApexPages.StandardSetController(Database.getQueryLocator(qry));
        List<SelectOption> allViews = ssc.getListViewOptions();
        for (SelectOption so : allViews) {
          if (so.getLabel() == listName) { 
          //for some reason, won't work with 18 digit ID
            listId = so.getValue().substring(0,15);
            break;
          }
        }             
    }     
  }
  public String listId {get;set;}
}

Apex Class

public class NitishContactListViewClass {

   public List<SelectOption> listViewNames{get; set;}
   public String conFilterName{get; set;}

   public NitishContactListViewClass(ApexPages.StandardController controller) {
       listViewNames = new List<SelectOption>();

       for(ListView lv :[SELECT Id, Name FROM ListView WHERE SObjectType='Contact' ORDER BY Name ASC]){
           listViewNames.add(new SelectOption(lv.Id, lv.Name));

      }
  }
}

Photo 1: Doesn't pull any results through even w/ thousands of contacts that fit the criteria (all Contacts, all users, no filters) enter image description here

Photo 2: What appears when we have our coded in error message from the Component. enter image description here

Photo 3: Stuck trying to load the list. After making suggested changes enter image description here

1
  • I know that an answer is accepted for your question but just wondering about the Photo 1, where we can see from the navigation menu that you are accessing the Visualforce page from Lightning UI. May I know what is the reason behind using a Visualforce page for this use case instead of a dynamic lightning component with lightning:listView ?
    – Shamina
    Apr 17, 2020 at 19:45

1 Answer 1

2

when you are passing value of selected list view to vf component why are you querying it again in NitishContactListViewController.apxc just use them

from the vfpage controller pass the 15 digit id to component and use those

public class NitishContactListViewClass {

   public List<SelectOption> listViewNames{get; set;}
   public String conFilterName{get; set;}

   public NitishContactListViewClass(ApexPages.StandardController controller) {
       listViewNames = new List<SelectOption>();

       for(ListView lv :[SELECT Id, Name FROM ListView WHERE SObjectType='Contact' ORDER BY Name ASC]){
           string ids=lv.Id;
           listViewNames.add(new SelectOption(ids.substring(0, 15), lv.Name));

      }
  }
}

vfc controller

public class NitishContactListViewController {
  public String listName {get; set;  }
  public String listId {get;set;}
}

in your component use listname attribute

  <apex:enhancedList type="Contact" height="5200" rowsPerPage="200" id="ContactList"
    listId="{!listName}" rendered="{!listName != null}" />
3
  • That helped get it to try to load. We aren't getting the same null error, which is good. However, it does get stuck loading now. I am attaching a picture of what it currently looks like when it tries to load. Any idea why it is getting stuck? Thank you! Apr 17, 2020 at 15:05
  • 1
    @wheeeeeecode i guess you are probably previewing the page directly put in on salesforce and test then
    – User6670
    Apr 17, 2020 at 15:11
  • We realized that shortly after as we refreshed the test page we've been using. It works! Apr 17, 2020 at 15:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .