Sunday 14 April 2013

URLFOR examples and explanations

Here are some uses of the apex URLFOR function :
    //Use $Action global varialble to access the New action reference -->
    <apex:outputLink value="{!URLFOR($Action.Account.New)}">New</apex:outputLink>
    //View action requires the id parameter, a standard controller can be used to obtain the id -->
    <apex:outputLink value="{!URLFOR($Action.Account.view, account.id)}">View</apex:outputLink>
    //Edit action requires the id parameter, id is taken from standard controller in this example -->
    <apex:outputLink value="{!URLFOR($Action.Account.Edit, account.id)}">Edit</apex:outputLink> 
    //Delete action requires the id parameter, also a confirm message is added to prevent deleting the record when clicked by mistake -->
    <apex:outputLink value="{!URLFOR($Action.Account.delete, account.id)}" onclick="return window.confirm('Are you sure?');">Delete</apex:outputLink>
    //From all custom buttons, links, s-controls and visualforce pages you can use the following to get the link of the object's homepage -->
    <apex:outputLink value="{!URLFOR($Action.Account.Tab, $ObjectType.Account)}">Home</apex:outputLink>
    //If your file is in another ZIP file, then pass the path of the file as id to URLFOR -->
    <apex:image url="{!URLFOR($Resource.CorpZip, 'images/logo.gif')}" width="50" height="50" />
    //reference to a custom VF page
    <apex:commandButton action="{!URLFOR($page.UpdateCouponReponse)}" value="Voir les coupons-réponse"/>
    //overriding standard page to add defaulted values
    <apex:page standardController="Filleul__c" action="{!URLFOR($Action.Filleul__c.New,null, [Name=$label.GenererNomAuto,retURL=$ObjectType.Filleul__c.KeyPrefix + '/o'],true)}">

No comments:

Post a Comment