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
um-dontaskmeum-dontaskme 

How can you use the records from a standard list controller in a SOQL query?

Sorry, I've spent several days digging, but I can't come up with it.  I'm probably missing something simple.

 

I have a Visualforce page that allows users to select their list of available Account views, then displays the accounts in that view.  I am displaying the list in a dataTable instead of a dataList, but otherwise it is just as described in the developer guide:

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_sosc_list_views.htm

 

For example, to create a simple list of accounts with a list view, create a page with the following markup:
<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>

 

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.

 

---------

 

But, I don't want to just display all the Accounts in the view.  I want to collect the records from that view and manipulate them in a controller extension.  Specifically, I want to gather them, add them to a list, then use SOQL to exclude some that are also part of a different list.  Then, I will use a dataTable to display the results of my final query.

 

I just can't figure out how to reference the Accounts in the selected view from the custom controller extension.  I know that on my Visualforce page, they are available as {!accounts}.  But, how do I pass that set of records or IDs from the selected view to my custom controller and gather them in a list?  Can anyone give me an example of the correct syntax to reference them?

 

Sorry if this is obvious, and thanks in advance for any help!!

 

Jon Mountjoy_Jon Mountjoy_

It sounds like what you want is a *custom* list controller - where you control the SOQL query. 

 

Check out this in the documentation as a start:

doc link

um-dontaskmeum-dontaskme

Right, that's definitely where I'm heading.  But, in this example, it appears they are ultimately still building the list from an independent SOQL query, not using the list of accounts from the view selected on the page.  I don't know how to write a SOQL query that references the Accounts in the current view {!accounts}, and I don't know how to pass the accounts in that view (filterid) to controller to build my own list of them that I could reference.

Message Edited by um-dontaskme on 03-17-2010 10:09 AM