function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
gopikrishnagopikrishna 

How to display multiple standard object with list views

Hi all,

 

          how to display list view with multiple standard objects in visual force page. 

 

I display only contact list views, but want display more than one standard object 

 

 

List Name List id

New This Week00B9000000464v7EAA
New Last Week00B9000000464vIEAQ
Platinum and Gold SLA Customers00B9000000464vZEAQ
Recently Viewed Accounts00B9000000464vhEAA
All Accounts00B9000000464viEAA
My Accounts00B9000000464vqEAA

 

so how to display multiple standard object list views 

 

my visual force page:

  

<apex:page standardController="contact" recordSetVar="contact" extensions="aaa">
<apex:pageBlock title="Account Lists">
<apex:form id="theForm">
<apex:pageBlockSection >
<apex:outputpanel >
<table class="list">

<tr>
<th >List Name</th>
<th>List id</th>
</tr>

<apex:repeat value="{!listviewoptions}" var="li">
<tr>
<td > <apex:outputText value="{!li.label}"></apex:outputText></td>
<td ><apex:outputText value="{!li.value}"></apex:outputText></td>
</tr>
</apex:repeat>

</table>
</apex:outputpanel>
</apex:pageBlockSection>
</apex:form>
</apex:pageBlock>
</apex:page>

Praveen Kumar 443Praveen Kumar 443
Please See Below Code:

Apex class :

public class ListViewController
{
    public list<selectoption> objectlist{set;get;}
    public string objectname{set;get;}
    public list<selectoption> viewoption{set;get;}
    public string listid{set;get;}
    
    public ListViewController()
    {
        objectlist = new list<selectoption>();
        objectname='Lead';
        objectlist.add(new selectoption('Lead','Lead'));
        objectlist.add(new selectoption('Account','Account'));
        objectlist.add(new selectoption('Contact','Contact'));
        viewoption= new list<selectoption>();
        getlistopt();
        
    }
    
    public pagereference getlistopt()
    {
        viewoption.clear();
        
        String q = 'SELECT Name FROM '+ objectname+' LIMIT 1';
        ApexPages.StandardSetController ACC = new ApexPages.StandardSetController(Database.getQueryLocator(q));
        List<SelectOption> ListViews = ACC.getListViewOptions();
        
        viewoption.addall(ListViews) ;
        return null;
    }
    

}


VF Page :-

<apex:page controller="ListViewController" >
  <apex:form >
      <apex:pageBlock >
          <apex:pageBlockSection >
              <apex:pageBlockSectionItem >
                  <apex:selectList value="{!objectname}" multiselect="false" size="1">
                      <apex:selectOptions value="{!objectlist}"></apex:selectOptions>
                      <apex:actionSupport action="{!getlistopt}" event="onchange" reRender="viewlist"/>
                  </apex:selectList>
              </apex:pageBlockSectionItem>
          </apex:pageBlockSection>
          <apex:outputPanel id="viewlist">
               <apex:pageBlockSection >
               <apex:pageBlockSectionItem >
                   <apex:selectList value="{!listid}" multiselect="false" size="1" onchange="alert(this.value)">
                      <apex:selectOptions value="{!viewoption}"></apex:selectOptions>
                   </apex:selectList>
                </apex:pageBlockSectionItem>
             </apex:pageBlockSection>
          
          </apex:outputPanel>
      </apex:pageBlock>
  </apex:form>
</apex:page>