Enhanced List View Component using Visualforce

This Component allows you to display a listView on a Visualforce page as shown,

Follow Instructions to setting up in your Org,

Visualforce Component

So this component takes Two input attributes,

  1. sObject Name
  2. ListView Name, (NOTE its label of listview but not developer name)
<apex:component controller="EnhancedListViewController">        
    <apex:attribute name="sObjectName" type="String" required="false" description="sObject Name" assignTo="{!objectName}"/> 
    <apex:attribute name="listViewName" type="String" required="false" 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}"> 
        <br /><br/>Could not find required ListView: <h3>'{!listName}'</h3>. on <h3>{!objectName}</h3> Please contact your administrator.
    </apex:outputText>    
</apex:component>

Controller

public with sharing class EnhancedListViewController{       
    public String objectName {get; set;}    
    public String listName { get; set;}    
    public String getlistId(){  
        try{
        ListView lv = [SELECT Id, Name, SobjectType FROM ListView where Name =: listName AND sObjectType =: objectName];
        string s = lv.Id;
        return s.substring(0, 15);
        } Catch(Exception Ex){
            return null;
        }
    }    
}

Sample Visualforce Page

This Visualforce page show how to use above component, as said we will pass two Input Attributes, in this scenario

  1. sObject => Opportunity
  2. Listview Labe => Won
<apex:page >      
    <c:EnhancedlistView_component sObjectName="Opportunity" listViewName="Won" />
</apex:page>

For sample output check top of page~

NOTE: If you pass wrong listView name its will shows you error message on page itself as shown

For more information on How to Create Apex Components/Apex Classes/Visualforce pages etc click here

Subscribe to Phanindra Mangipudi

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe