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
wsthesiswsthesis 

"View" Filters on Home Tabs

On many of the "home" tabs (ex) leads, contacts, accounts, opportunities) underneath the initial header, there is a
View: ____drop down list_______ [Go] {Edit Link} {Create New View}

I want to programmatically (using visual force or apex code) recreate this same drop down list in a new apex controller/visualforce page.
1. Where in the schema is this view information stored? What's the SOQL object name (or field(s)) to get this list of views (for use in a SOQL query)?
2. Is there an apex tag that renders this list?
Sorry for the double post in apex code/visual force, but I'm unsure which boundary it falls into. Thanks in advance.
 
MATTYBMEMATTYBME
This is from the Visualforce developer guide and maybe what you are looking for.


"For example, to create a simple list of accounts with a list view, create a page with the following markup:
Code:
<apex:page standardController="Account" recordSetvar="accounts">
<apex:pageBlock title="Viewing Accounts">
<apex:form id="theForm">
<apex:panelGrid columns="2">
<apex:outputLabel value="View:"/>
<apex:selectList value="{!filterId}" size="1">
<apex:actionSupport event="onchange" rerender="list"/>
<apex:selectOptions value="{!listviewoptions}"/>
</apex:selectList>
</apex:panelGrid>
<apex:pageBlockSection >
<apex:dataList var="a" value="{!accounts}" id="list">
{!a.name}
</apex:dataList>
</apex:pageBlockSection>
</apex:form>
</apex:pageBlock>
</apex:page>

When you open that page, you'll see something like the following:



This page is associated with the standard account controller and the apex:selectlist component is populated by {!listviewoptions}, which evaluates to the list views the
user can see. When the user chooses a value from the drop-down list, it is bound to the filterId property for the controller.
When the filterId is changed, the records available to the page changes, so, when the apex:datalist is
updated, that value is used to update the list of records available to the page.

You can also use a view list on an edit page, like the following:"

Code:
<apex:page standardController="Opportunity" recordSetVar="opportunities" tabStyle="Opportunity"
sidebar="false">
<apex:form>
<apex:pageBlock>
<apex:pageMessages/>
<apex:pageBlock>
<apex:panelGrid columns="2">
<apex:outputLabel value="View:"/>
<apex:selectList value="{!filterId}" size="1">
<apex:actionSupport event="onchange" rerender="opp_table"/>
<apex:selectOptions value="{!listviewoptions}"/>
</apex:selectList>
</apex:panelGrid>
</apex:pageBlock>

<apex:pageBlockButtons>
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!opportunities}" var="opp" id="opp_table">
<apex:column value="{!opp.name}"/>
<apex:column headerValue="Stage">
<apex:inputField value="{!opp.stageName}"/>
</apex:column>
<apex:column headerValue="Close Date">
<apex:inputField value="{!opp.closeDate}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 
Hope that helps.


Message Edited by MATTYBME on 12-16-2008 06:14 AM
mtbclimbermtbclimber
As for boundaries, generally if within your question anything involves Visualforce then it's a Visualforce question until proven otherwise.  Please don't spam the boards. One of the moderators will move the message to the best forum if you put it in the wrong place.
wsthesiswsthesis
Matt,
 
Thanks for the info. The code segment by itself does shows the list(s) that I want and how to manipulate it only using VisualForce.
Formally, I did not realize that this is called a list view.
 
For example, I select this particular view list option (filterListId = 00B40000005ZTJL):
<option value="00B40000005ZTJL">My opportunities</option>
 
It returns the following opportunity ids via visualforce:
006R0000002evRwIAI
006R0000002fPJXIA2
006R0000002fPJdIAM
006R0000002fPJcIAM
006R0000002evZEIAY
006R0000002evZ5IAI
 
 
My (clarified) question:
Assume that I saved this list view id value in my controller. In my controller, is there anyway to query for the "list view's" associated accounts/opportunities/etc.?

I want to use this view list's opportunities (all 6 opportunity ids in my example) in other controller methods.

A. Is there an apex "helper method" that already contains these opportunity ids?
B. Is there a way to grab these opportunity ids for use as part of a bind variable in a SOQL query?


Administrator: I'm not sure now if my question really falls into Visualforce anymore. Please rename the subject and/or move if necessary. Thanks!
mtbclimbermtbclimber
In your controller extension you simply have to call getRecords() on the standardsetcontroller and cast the results to the appropriate type.


wsthesiswsthesis

Andrew,

Thanks for your response, but I'm confused by the implementation.
I understand that it will return (in my case) a list of Opportunities. But, realize that it is a subset of the full list of opportunities (as per the definition of "list view options". My interpretation is as follows:

---------------------

Code:
visualforce code snippet:
<apex:outputLabel value="Opportunity Lists" />
 <apex:selectList value="{!filterListId}" size="1">
  <apex:selectOptions value="{!listviewoptions}">
 </apex:selectOptions>
</apex:selectList>

controller code:

 public List<Opportunity> dataList
 {
  get 
  {
   return (List<Opportunity>)controller.getRecords(); 
  } 
  set; 
 }

    public String filterListId
    { get; set; }


 


---------------------
How will I be able to filter the records that were selected in the visualforce (view) page? How does getRecords() know what filter was selected? Is this supported?

SOQL query within controller code:

Code:
        List<Opportunity> oids = this.dataList;

        opportunities =
                    [select o.AccountId 
                    from Opportunity o
                    where o.id in :oids];
        
        // convert into list of account ids
        for (Opportunity o: opportunities)
        {
            opportunityIds.add(o.accountid);
        }


 
Please let me know if you need me to clarify. Thanks in advance.

mtbclimbermtbclimber
You need to add actionSupport to handle the onchange event for the select list.  This will notify the controller that the filterId has changed. You'll also need to bind the selectlist value to the filterId property on the standardsetcontroller as well.