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.Action
s 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.