3

From a List Button or Visualforce Page, I wanna redirect to a ListView after. Common, right?

Life is great when we're dealing with Standard Controller: using view() method.

What is the correct, documented, future-proof way to do this from a Standard Set Controller?

public PageReference back() {

    //this seems so fragile and lightning-unfriendly: "/001?fcf=00B24000004cfLK"

    SelectOption listViewOption = controller.getListViewOptions()[0];

    PageReference pr = new PageReference('/' + SObjectType.Account.KeyPrefix);

    pr.getParameters().put('fcf', listViewOption.getValue().left(15));

    return pr;

}

I had some some ideas using ApexPages.Action but they caused kooky Internal Salesforce Errors:

public PageReference back() {

    String expression = '{!URLFOR($Action.My__c.List, $ObjectType.My__c)}';

    ApexPages.Action action = new ApexPages.Action(expression);

    return action.invoke();

}
2

Whoa. This works:

public PageReference listView() {

    return new ApexPages.Action('{!List}').invoke();
    //System.PageReference[/a09?fcf=00B24000004cfLK]

}

But is it documented?

  • 1
    Not explicitly with {!list} but it is here: developer.salesforce.com/docs/atlas.en-us.apexcode.meta/… - it shows {!save} AND developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/… - shows list so you have to infer the items together to get to where you got – Eric Oct 20 '15 at 2:22
  • 1
    nope, I did not even catch that.....But i believe they share the same prototype object or something...no expert at all here but it would appear based on what you found that there is something shared between them – Eric Oct 20 '15 at 2:25
  • 1
    StandardSetController objects allow you to create list controllers similar to - So a set controller lets you create a list controller(s) so just a set of lists lol - no wonder we get confused...Please tell me if I am completely wrong here, just trying to help, not trying to say I know anything – Eric Oct 20 '15 at 2:33
  • 1
    Have you attempted to compile while using a standard set controller and attempting to execute the list() method? Would be interesting if it compiled and validate what you are seeing. Wish I was near an org ATM – Eric Oct 20 '15 at 2:59
  • 1
    lol - As Microsoft would say - Working as designed..... – Eric Oct 20 '15 at 3:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.