When building links in Visualforce, I typically prefer using the $Action global variable and URLFOR(). e.g.:
<apex:outputLink value="{!URLFOR($Action.Account.View,Account.Id)}" >
As far as I can tell, these actions are specific to an object, and there aren't actions available that work on the generic SObject. There is however a dynamic syntax that can be used. The problem then being that not every object will support that action. You might think that if a record has been viewed that the object will support the view action, but that is unfortunately not the case for some object types:
Field $Action.ListView.View does not exist. Check spelling
Error is in expression '{!URLFOR($Action[rv.Type].View,rv.Id)}' in component in page analysis:recentlyviewed
If a Visualforce page has a collection of Ids that could be from different records, is there an effective way to use the $Action global variable?
Controller
public class RecentlyViewedController{
public list<RecentlyViewed> getRecentlyViewed(){
return [SELECT Id, Name, Type FROM RecentlyViewed LIMIT 20];
}
}
Page
<apex:page controller="RecentlyViewedController">
<apex:pageBlock>
<apex:pageBlockTable data="{!RecentlyViewed}" var="rv">
<apex:column headerValue="{!$ObjectType.RecentlyViewed.fields.Name.Label}">
<apex:outputLink value="{!URLFOR($Action[rv.Type].View,rv.Id)}">
<apex:outputText value="{!rv.Name}" />
</apex:outputLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>