How to specify an Action for an URLFOR in apex

I have the following command link:

<apex:commandLink value="Edit" action="{!URLFOR($Action.Contact.Edit, rec.id)} />

Which works fine. But I’m trying to make the code generic, to work with multiple objects (not just Contact), so I’d like to specify the action from my controller. Based on the docs for ApexPages.Action, I tried the following:

<apex:commandLink value="Edit" action="{!URLFOR(RecordEditAction, rec.id)} />

With this in the controller:

public ApexPages.Action getRecordEditAction() {
    return new ApexPages.Action('{!$Action.Contact.Edit}');
}

As a test, planning to compute the actual string in the final code. But the test above gives me an “Incorrect argument type for function URLFOR()” error when trying to save the VF page. Looks like ApexPages.Actions are intended to be passed directly as an action param, that is, not via URLFOR, but then there’s no way to specify to which object id to apply the action.

How can I specify the desired action from Apex? I don’t want to use an url hack (e.g., 003/e); other uses may include delete actions, etc.

Answer

I think this is what you are looking for:

http://www.salesforce.com/us/developer/docs/pages/Content/pages_dynamic_vf_globals_action.htm

Attribution
Source : Link , Question Author : Jason Clark , Answer Author : KoenVM

Leave a Comment