Skip to content

Instantly share code, notes, and snippets.

@jeffdonthemic
Last active February 14, 2019 03:07
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jeffdonthemic/e9f06eaa2541bf716f3e to your computer and use it in GitHub Desktop.
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