+ Start a Discussion
srikeerthisrikeerthi 

Reg: LIstVIew on VF Page

Hi

 

I need to get only List View of an Object on VF page.Is it possible to get only those 

picklist values that are in list view of a particular object.

 

 

Thanks

SalmanSalman
Hii Srikeerthi,
 To get listview of any object use standardsetController 
for example if your object is Opportunity then 
Vf page is
===============
<apex:page standardController="Opportunity" recordSetVar="Opportunity" extensions="AccountListViewExtension" >
   <apex:form >
   <apex:pageBlock >
  <apex:selectList label="Opportunity View"  value="{!selectedFilterId}" size="1" id="filterMenu">
            <apex:selectOptions value="{!filters}"></apex:selectOptions>
            <apex:actionSupport event="onchange"  action="{!resetFilter}"  status="ajaxStatus"/> 
       </apex:selectList><br/>
      </apex:pageBlock>
  </apex:form>
 </apex:page>
=========================
Controller is
+++++++++++++++++++
public with sharing class AccountListViewExtension
{
    public String selectedFilterId { get; set; }
     public List<SelectOption> filters { get; private set; }
    public List<ListView> FilterId2 {get; set;}
    public ApexPages.StandardSetController controller{get;set;}
    public  List<SObject> listViews {get;set;}
    public  List<OpportunityContactRole> a1{get;set;}
    
    public AccountListViewExtension(ApexPages.StandardSetController controller) {
        //to get the view of object
         filters = controller.getListViewOptions();
       //Filterid is basically when view you selected
         selectedFilterId = controller.getFilterId();
         FilterId2=[SELECT Name,id FROM ListView WHERE id = :selectedFilterId ];
         //getRecords is to get all records from a listview
         List<SObject> listViews = controller.getRecords();
      //iterate to get Opportunity records and contact roles
         for(SObject listView : listViews) {
        String a = listView.id;
       
        List<OpportunityContactRole> a1 = [Select id,Role From OpportunityContactRole Where OpportunityId =:a];  
    }
    }
    Thank you
   Salman