Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code for ContactListViewComponents for enhancedList Visualforce component. http://blog.jeffdouglas.com/2014/12/12/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."/>
</apex:component>
public with sharing class ContactListViewController {
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:page>
<c:ContactListViewComponent listViewName="Super Special Contacts"/>
</apex:page>
@isTest
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
You can’t perform that action at this time.