• Vasily
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies

Hello,

I faced issue working with views functionality. By "views" i mean : if you Click Leads tab for instance
you will see dropdown with existing views and ability edit/create new views.

So my task is very similar.I need develop custom "view" functionality.
-I need to receive existing views and add them to dropdown.
-On changing some view from dropdown i need select data based on particular filter criteria.

Please take a look at my testing code . Issues are marked in red color.
So there are two issues in code below:
1) setFilterId does not filter records :   ssc.setFilterID( this.m_SelectedView);
2) can't call size() method for getListViewOptions (exception raised) : List<SelectOption> result = ssc.getListViewOptions();

 


Code:
// Controller

public class TestViewPageController

{

private string m_SelectedView = '';



// Gets the selected view id.

public string getSelectedView()

{

return this.m_SelectedView;

}



// Sets the selected view id.

public void setSelectedView( string value )

{

this.m_SelectedView = value;

}



// Gets a list of users’ views. In order to display in drop down.

public List<SelectOption> getViewsList()

{

List<User> users = [SELECT id FROM User];



ApexPages.StandardSetController ssc = new ApexPages.StandardSetController( users );



List<SelectOption> result = ssc.getListViewOptions();



if ( null == this.m_SelectedView || '' == this.m_SelectedView)

{

/* Set the default selected view value. Code commented because raise error. Error always occurs when we

try access result collection. In that particular case exception will be trown trying to access result.size()



if result.size() > 0 )

{

this.m_SelectedView = result.get(0).getValue();

}

*/

}



return ssc.getListViewOptions();

}



// Gets a list of the users in the view.

public List<User> getUsers()

{

// Returns a empty list of users if view not selected.

if ( null == this.m_SelectedView || '' == this.m_SelectedView)

{

return new List<User>();

}



List<User> users = [SELECT id, name, email FROM User]; // SOQL



ApexPages.StandardSetController ssc = new ApexPages.StandardSetController( users );



// Sets a filter id value.

ssc.setFilterID( this.m_SelectedView);



// Should return filtered records but returns a list of records defined by SOQL. (All users)

return (List<User>)ssc.getRecords();

}



}



// Layout:





<apex:page controller="TestViewPageController" >



<apex:form >



<apex:pageBlock title="Title">



<apex:pageBlockButtons location="top">



<apex:selectList value="{!SelectedView}" multiselect="false" size="1">



<apex:selectOptions value="{!ViewsList}" />



<apex:actionSupport event="onchange" rerender="users" />



</apex:selectList>



</apex:pageBlockButtons>



<apex:outputPanel id="users">



<apex:pageBlockTable value="{!Users}" var="entry" width="100%">



<apex:column headertitle="Id" value="{!entry.Id}" />



<apex:column headertitle="Name" value="{!entry.Name}" />



<apex:column headertitle="Email" value="{!entry.Email}" />



</apex:pageBlockTable>



</apex:outputPanel>



</apex:pageBlock>



</apex:form>



</apex:page>


 

 

 Thanks in advance

 

 



Message Edited by Vasily on 10-10-2008 06:48 AM

Message Edited by Vasily on 10-10-2008 06:49 AM

Message Edited by Vasily on 10-13-2008 02:08 AM

Message Edited by Vasily on 10-13-2008 02:12 AM
  • October 10, 2008
  • Like
  • 0