While developing your Visualforce pages you may need to be able to obtain the URL of certain actions, s-controls or your static resources.

I found it personally a challenge since the documentation for "URLFOR" function is not included in "Visualforce Developer Guide" itself and instead included in the general help area of Salesforce.

Generally you can use the "URLFOR" function for three purposes:

  1. Obtain URL of a s-control
  2. Obtain URL of a static resource
  3. Obtain URL of an object's action

In this article I will demonstrate usages of the three above.

Generally, URLFOR function returns a relative URL for an action, s-control, or a file in a static resource archive in a Visualforce page. Following the syntax of the function:

{!URLFOR(targetid, [inputs], [no override])}

Parameters shown in brackets ([]) are optional.

  • target: You can replace target with a URL or action, s-control or static resource.
  • id: This is id of the object or resource name (string type) in support of the provided target.
  • inputs: Any additional URL parameters you need to pass you can use this parameter.
    you will to put the URL parameters in brackets and separate them with commas
    ex: [param1="value1", param2="value2"]
  • no override: A Boolean value which defaults to false, it applies to targets for standard Salesforce pages. Replace "no override" with "true" when you want to display a standard Salesforce page regardless of whether you have defined an override for it elsewhere.

Obtaining URL of a s-control:

<!-- Use $SControl global veriable to reference your s-control and pass it to the URLFOR function -->
<apex:outputLink value="{!URLFOR($SControl.MySControlName)}">Link to my S-Control</apex:outputLink>

Obtaining URL of a Static Resource

<!-- Use $Resource global veriable to reference your resource file -->
<apex:image url="{!URLFOR($Resource.LogoImg)}" width="50" height="50" /> <!-- 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" />

Obtaining URLs of an Object's Actions:
In order to get URL of the an object's actions you need to know what actions that object supports. Below are some of the common actions most Objects support:

  • View: Shows the detail page of an object
  • Edit: Shows the object in Edit mode
  • Delete: URL for deleting an object
  • New: URL to create a new record of an object
  • Tab: URL to the home page of an object

However, each object may support additional actions for example Contactalso supports "Clone" action and Case supports "CloseCase" action.

<!-- Use $Action global varialble to access the New action reference -->
<apex:outputLink value="{!URLFOR($Action.Account.New)}">New</apex:outputLink>
<br/>
<!-- 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>
<br/>
<!-- 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>
<br/>
<!-- 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>
<br/>
<!-- 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>

最新文章

  1. WordPress基础:固定链接的设置
  2. MySql视图、存储过程、函数、索引
  3. 如何居中一个div?
  4. Codeforces 55D (数位DP+离散化+数论)
  5. selenium项目总结(UI自动化测试平台搭建、测试报告生成、邮件转发)
  6. C# 工厂
  7. 回调函数与DOM事件
  8. Struts2的零配置和rest插件
  9. 终于有人把O2O、C2C、B2B、B2C的区别讲透了
  10. hdu3516
  11. c++ 对象指针参数和对象引用参数02
  12. Oracle中的游标的原理和使用详解
  13. Nginx Upstream模块源码分析(上)
  14. 前端项目git操作命名规范和协作开发流程
  15. PHP操作RabbitMQ的类 exchange、queue、route kye、bind
  16. MSSQL-sql server-视图简介
  17. 线程的定时器Timer
  18. 【 PostgreSQL】查询某模式下所有表的分布键信息
  19. Unity3D学习笔记(二十七):MVC框架下的背包系统(2)
  20. java执行jar包出错:Unable to access jarfile

热门文章

  1. FreeBSD_11-系统管理——{Part_4 - 内核参数定制}
  2. 2287: 【POJ Challenge】消失之物
  3. lua 入门学习
  4. python基础语法(1)
  5. 如何查看 oracle 官方文档
  6. CobarClient源码分析(1)
  7. 解决Win7下打不开chm文件的方法
  8. 《精通Matlab神经网络》例10-16的新写法
  9. ubuntu 挂载新硬盘
  10. Google Chrome: Make the Bookmarks Bar Display as Icons Only