Bit of a shot in the dark, but try calling setFilterId
on your StandardSetController
to get more deterministic behavior.
public static final String DESIRED_LISTVIEW_LABEL = 'All';
public SomeClass(ApexPages.StandardSetController controller)
{
if (!controller.getSelected().isEmpty())
return [SELECT Name FROM MyObject__c WHERE Id IN :controller.getSelected()];
for (SelectOption listViewOption : controller.getListViewOptions())
{
if (listViewOption.getLabel() == DESIRED_LISTVIEW_LABEL)
{
controller.setFilterId(listViewOption.getValue());
break;
}
}
// do stuff
}
You can also expose the available filters ( List<SelectOption>
) returned from getListViewOptions()
as a property on your controller and let the end user decide which list view they want.
Update Lightning does not support Javascript buttons.
You do not need to add an extra user input step. Instead of making DESIRED_LISTVIEW_LABEL
final, you can get it through page parameters if you make your list button Execute Javascript
as follows:
(function (w) {
"use strict"
var fcf, index, payload, search = window.location.search,
params = search.substring(1, search.length).split('&');
for (i in params) {
payload = params[i].split('=');
if (payload[0] == 'fcf') {
fcf = payload[1];
break;
}
}
w.open('/apex/MyPage?ListView=' + fcf);
})(window);
You could simplify the above somewhat since fcf
seems to be the only parameter most of the time, but I tried to make it robust against future changes in the url. Then you can do:
public static final String LISTVIEW_PARAM = 'ListView';
public Id desiredFilterId
{
get
{
return ApexPages.currentPage().getParameters().get(LISTVIEW_PARAM);
}
}
public SomeClass(ApexPages.StandardSetController controller)
{
if (!controller.getSelected().isEmpty())
return [SELECT Name FROM MyObject__c WHERE Id IN :controller.getSelected()];
if (String.isNotBlank(desiredFilterId))
controller.setFilterId(desiredFilterId);
// do stuff
}