5

I need to add a link to a VF page which opens the current page with an additional parameter (to allow an embedded VF page to redirect to itself as a non-embedded page). I have this, which works:

<apex:commandLink action="{!URLFOR('/apex/ListPage', id, [id=id, fullpage='1'])}" 
                   value="Full List" />

This works fine, but I don't want the hardcoded page name. I've tried $CurrentPage ("Incorrect Argument type for function URLFOR"), $CurrentPage.url ("Invalid target parameter for function URLFOR), and even $CurrentPage.geturl ("Field getUrl does not exist", which proves that $CurrentPage.url refers to something). $CurrentPage.name compiles (I can save the page) but clicking the resulting link gives the error, "Formula Expression is required on the action attributes."

The other option that works is $Apex.ListPage, but while it's not a string, it's still specific to the page name; I'd prefer something that would work in any page without edits. Possible?

aside: I'm passing the id as second param, but it was being ignored, so I added it to the extra param array, and it works fine. Not sure why that's needed, but it's working.

3
  • Why commandLink and not outputLink? Looks like you just want to start fresh, with new params passed via url. So regular link without commandLink / commandButton "side effects" should be OK and more forgiving ;). Another option might be to use embedded <apex:param>s (don't make the link a self-closing tag)
    – eyescream
    Jan 17, 2014 at 19:10
  • Can you use {!URLFOR('/apex/' + $CurrentPage.Name, ...)}? Jan 17, 2014 at 19:11
  • @user320 yep, prefixing '/apex/' did the trick. Accepted. Jan 17, 2014 at 19:18

1 Answer 1

12

Something like this what you're looking for?

{!URLFOR('/apex/' + $CurrentPage.Name, null, ['id'=id])}

It will compile into URLFOR alright, and resolve to an absolute URL including namespace:

https://namespace.na14.visual.force.com/apex/Relative?id=000000000000000AAA

I'm passing the id as second param, but it was being ignored, so I added it to the extra param array, and it works fine. Not sure why that's needed, but it's working.

I think that second parameter is strictly for $Action URLs. Otherwise it's dropped.

6
  • 3
    Ah further mysteries of the URLFOR function explained! :-) Jan 17, 2014 at 19:18
  • 1
    Seems silly that $Page.PageName works, but $CurrentPage doesn't. Mysteries indeed! Jan 17, 2014 at 19:20
  • re: StandardController - The page in question uses a standard controller and a controller extension. Jan 17, 2014 at 19:34
  • Derp >.< fixed - my bad @JasonClark Jan 17, 2014 at 19:40
  • 1
    For other URLFOR mysteries, I find myself referring to this page all the time: salesforcesource.blogspot.com/2008/12/… Jan 17, 2014 at 19:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .