[SalesForce] Using URLFOR() to refer to the current page dynamically

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.

Best Answer

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.

Related Topic