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
Steven Buelow 17Steven Buelow 17 

Can I override the last list Filter viewed on a StandardObject Controller on instantiation without a custom controller?

Hi, I'm actually trying to find out if there is an easy way to do this. I'm looking to use as much non-custom class salesforce as possible. 

I'd like to create a Apex:Page.StandardController:User that does something like this:
<apex:pageBlock> <apex:pageBlockTable value="{!users}" var="a" > <apex:column value="{!a.name}"/> <apex:column value="{!a.ProfileId}"/> <apex:column value="{!a.UserRoleId}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:page>


But as I've read, vaguely, the system defaults to the last viewed Filtered list of that Object Type.  We're instructed to use something like this: 
 
<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>


My Question: Can I programatically set  the fcf value on the StandardObject User as it pulls the information for the view? I DON'T want this to be user selected. I'd like it to be a forced selection that whenever they'd go to a specific page, they'd get a specific view.

Can this be done without a custom controller OR any .JS hacking?

I was hopeing for something like 
 
<apex:page standardController="User" recordSetVar="users" tabstyle="user" sidebar="false" fcf="00Bo0000002sTnZ">

 
bob_buzzardbob_buzzard

This is a little more tricky that it might appear at first glance - you have to assign a value to the controller property 'filterId' and there isn't a standard component that supports this.
I use a simple custom component as follows:

<apex:component >
    <apex:attribute name="from" type="String" assignTo="{!to}" description="The value to set"/>
    <apex:attribute name="to" type="String" description="The variable to set the value into"/>    
</apex:component>
and then set this from the page as follows:
<c:SetValue from="00Bo0000002sTnZ" to="{!filterID}"/>
It has a somewhat clunky feel to it, but works.
Steven Buelow 17Steven Buelow 17
Bob, this works. I'll elaborate what you are doing, correct me if I'm wrong... I'm doing this because I know there are a lot of intro code folks who don't know how to write unit tests and are terrified of custom classes. Assuming this doesn't require a unit text, it's definitely a decent hack.

Go to Settings>Develop>Components and we see the "Visualforce Components" at the top of the page. Create a new component. Paste in your above code as is: 
<apex:component >
    <apex:attribute name="from" type="String" assignTo="{!to}" description="The value to set"/>
    <apex:attribute name="to" type="String" description="The variable to set the value into"/>    
</apex:component>  
<!--Courtesy of Bob_Buzzard -->
Then go to your visualforce page and paste in :
<c:SetValue from="00Bo0000002sTnZ" to="{!filterID}"/>
<!--Courtesy of Bob_Buzzard -->
* from will equal whatever page you want to reference (you find it by looking at your URL bar and copying the fcf="somestring"
 for those who are super green.

Now everytime you load your page it automatically would set the custom list you have created on the Account, Opportunity, or whatever. Custom lists view being the pull down list you see when you click on the standard Tab of accounts or opportunities.

Bonus: It doesn't actually change the view pull down list, so you can run it and not have to worry about your View tab changing.



Why do all this?
  1. You can use the standard admin level report and report filtering strategies you probably use every day in making custom reports from the GUI.
  2. It knows the users record view access from what I can tell, so people who shouldn't see the data still shoulding, while a custom query may not always behave in this way and you'd have to add some logic there to check that.
  3. This should be a standard setter method of the Sobject considering it's doing it anyways with {filterId}
  4. You don't have to make a custom class or know a ton about MVC to make this work... I know a lot of people out there want to customize salesforce in very slight ways and this helps (mainly since we can't simply request reports values and load them into an object)
Bob feel free to pile on and correct me, obviously, I've outlined this assuming more people are like me (novice apex users) and less are like you (smart code writers who understand some of the odd nuances of this language).