Sunday, May 17, 2009

URLFOR() explained

Although this is a very useful function in Salesforce.com, it is not properly documented.

Few days ago, I found a very good blog that explains this function, I have decided to summarize Sam Arjmandi’s article, but for full details please visit his article here.

URLFOR function returns a relative URL using this syntax:

{!URLFOR(target, id, [inputs], [no override])}
Target: Action, s-control or static resource.
Id: Resource name (string type) or record ID (depends on the “target”).
Inputs: Additional parameters passed. Format: [param1="value1", param2="value2"]
No override: A Boolean flag. Set to true if to display a standard Salesforce page regardless of whether you have defined an override for it elsewhere. (default false)

So, how to use this function for files and folders ?

Resource file: URLFOR($Resource.LogoImg)
Resource zip file or folder: URLFOR($Resource.CorpZip, 'images/logo.gif')

But equally important, is that the URL for actions that can be performed on custom and standard objects can be easily found using this function. These actions are implemented by all objects:

View record: URLFOR($Action.Account.View, account.id)
Create new record: URLFOR($Action.Account.New)
Edit record: URLFOR($Action.Account.Edit, account.id)
Delete record: URLFOR($Action.Account.Delete, account.id)
View List: URLFOR($Action.Account.Tab, $ObjectType.Account)

Note that some objects support other additional actions; for example Contact also supports "Clone" and Case also supports "CloseCase" action. To find out which action can be invoked on a particular object, check the buttons and links which can be overridden for that object. For standard objects go to Setup > App Setup > Customize > Desired Standrd Object > Buttons and Links and you will see a page like this:

Just use the name of the function like this: URLFOR($Action.Object.Name, Object.ID)

No comments:

Post a Comment