Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Code for ContactListViewComponents for enhancedList Visualforce component.
<apex:component controller="ContactListViewController">
<apex:attribute name="listViewName" type="String" required="true"
description="The name of the listview." assignTo="{!listName}"/>
<apex:enhancedList height="400" rowsPerPage="25" id="ContactList"
listId="{!listId}" rendered="{!listId != null}" />
<apex:outputText rendered="{!listId == null}" value="Could not find requewed ListView: '{!listName}'. Please contact your administrator."/>
public with sharing class ContactListViewController {
public String listName {
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);
public String listId {get;set;}
<c:ContactListViewComponent listViewName="Super Special Contacts"/>
private class TEST_ContactListViewController {
private testMethod static void testSuccess() {
ContactListViewController con = new ContactListViewController();
con.listName = 'Super Special Contacts';
System.assert(con.listId != null);
private testMethod static void testFailure() {
ContactListViewController con = new ContactListViewController();
con.listName = 'BADLISTNAME';
System.assert(con.listId == null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment