Last active
February 14, 2019 03:07
-
-
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page> | |
<c:ContactListViewComponent listViewName="Super Special Contacts"/> | |
</apex:page> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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