+ Start a Discussion
SuriSuri 

StandardSetController - setFilterId Issue

Hello,

I am having an issue using the StandardSetController in a VF page for displaying the records from different List Views on Accounts, especially with the setFilderID(String) method.

What my Page does:
It basically just shows all the available List Views on Accounts using the StandardSetController.getListViewOptions() method.

Then the User selects the desired view, it simply sets the StandardSetController.setFilterID() to the selected View ID.

This seems to work fine in most cases, but here is the problem sometimes.

Problem:

For example let's say my List View is "X" with Criteria: Name startsWith Test
- When the StandardSetController.setFilterID() is set to this view, it ALWAYS displays ALL Accounts in the System. The List View filter criteria does not seem to be respected.

HOWEVER, if I just change the SAME List View "X" Criteria to: Name startsWith Sample, the StandardSetController.setFilterID() works perfectly fine.
- and shows me the correct accounts with Names starting with "Sample..."

My conclusion:
The setFilterID() seems to fail in certain cases depending on the VALUE entered in the View Filter (not necessarily on the Field).

Does ANYONE have ANY idea how to solve this?

I tried logging a Case to salesforce already but no viable solution from them yet.

Thanks,

Suri
AmitAmit (Salesforce Developers) 
Hello,

There had been similar issues we had come across, and this issue is mentioned at known issue site :

https://success.salesforce.com/issues_view?id=a1p30000000T3SSAA0 As of now

Workaround is :

Try creating a SOQL query to explicitly load the record you are interested in, and not really on the filter Id. So, something like this in their Controller:
List members = [select AccountId from AccountTeamMember where UserId = :UserInfo.getUserId()];
List accountIds = new List();
for (AccountTeamMember member : members) {
accountIds.add(member.AccountId); }
setCon = new ApexPages.StandardSetController(database.getQueryLocator('select name from Account where Id in :accountIds'));"
SuriSuri
HI Amit,

Please read my question again :)

The solution you've suggested is a very specific case for "AccountTeamMember",
and in my opinion it doesn't even make sense to my problem - apples and oranges. :)

What it talks about is a way to get the Account Team Members, which is of absolutely no use to us here. (and moreover my org is not enabled with Account Team Members)

We specifically need to be able to retrieve Accounts belonging to different User-Defined List Views - and in Apex, the only way to do this as of now is by using the StandardSetController.SetFilterId method.

If there any other way to access this Filter Criteria of ListViews in Apex, please let us know.
(In my opinion, it is not possible to retrieve these filters in any other way other than StandardSetController in Apex,
although it is accessible via the Metadata API but we can't use the Metadata API here)

We have logged a Case with Salesforce, and this has been identified by them as a BUG which will be fixed in the next Release.