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>

[salesforce] URLFOR function finally的更多相关文章

  1. [salesforce] standard button

    Use Case In Salesforce, when you click on the standard ‘New’ button on a Related List to create a ne ...

  2. 通过百度echarts实现数据图表展示功能

    现在我们在工作中,在开发中都会或多或少的用到图表统计数据显示给用户.通过图表可以很直观的,直接的将数据呈现出来.这里我就介绍说一下利用百度开源的echarts图表技术实现的具体功能. 1.对于不太理解 ...

  3. salesforce零基础学习(八十)使用autoComplete 输入内容自动联想结果以及去重实现

    项目中,我们有时候会需要实现自动联想功能,比如我们想输入用户或者联系人名称,去联想出系统中有的相关的用户和联系人,当点击以后获取相关的邮箱或者其他信息等等.这种情况下可以使用jquery ui中的au ...

  4. Salesforce视图与控制器之间的交互

    刚接触Salesforce,过程的确是比较艰难了,中文资料几乎没有,看英文资料学的效率却不高,不过看了一段时间的英文资料发现自己英语水平挺高不少啊,现在看都不用工具翻译,早知道就再次尝试报个6级,看下 ...

  5. iOS Salesforce SDK 小知识

    Salesforce SDK 能做许多任务,因此也比较繁杂,又分了原生,js等多个调用方法. 关键点总结: SFSmartStore 中的 - (id) initWithName:(NSString* ...

  6. Salesforce 数据清洗

    新系统上线后,需要导入历史数据,但是旧数据格式,数据缺失,数据错误,奇异值,属性归类与新系统有很大的gap.因此我们需要建立一套数据动态清洗规则给Salesforce系统,通过这些规则自动清洗导入数据 ...

  7. Salesforce 动态审批

    由于Salesforce只支持根据条件动态选择审批分支,如果我们想进一步支持动态根据页面的某种条件选择审批人,Salesforce是不支持的.因此我们只能通过override salesforce审批 ...

  8. Salesforce + AngularJS + Bootstrap

    也可以分成三步: 1. 添加css和js引用: <apex:stylesheet value="https://maxcdn.bootstrapcdn.com/bootstrap/3. ...

  9. salesforce 零基础学习(二十八)使用ajax方式实现联动

    之前的一篇介绍过关于salesforce手动配置关联关系实现PickList的联动效果,但是现实的开发中,很多数据不是定死的,应该通过ajax来动态获取,本篇讲述通过JavaScript Remoti ...

随机推荐

  1. java动态加载类和静态加载类笔记

    JAVA中的静态加载类是编译时刻加载类  动态加载类指的是运行时刻加载类 二者有什么区别呢 举一个例子  现在我创建了一个类  实现的功能假设为通过传入的参数调用具体的类和方法 class offic ...

  2. Ubuntu系统监控cpu memery 磁盘Io次数 IO速率 网卡 运行时间等信息的采集

    实验室最近在做的项目要做ubuntu系统监控,要获得系统的一些信息并返回给web服务器. web服务器与ubuntu主机的通信我写的程序用的是socket,至于为什么不用java程序ssh到对应的主机 ...

  3. 线程学习笔记 等待句柄和线程池(摘自https://blog.gkarch.com/threading/part2.html#manualresetevent)

    //如果你的应用有很多线程,这些线程大部分时间都在阻塞,那么可以通过调用ThreadPool.RegisterWaitForSingleObject来减少资源消耗.这个方法接受一个委托,它会在向等待句 ...

  4. js 页面值变动监听

    1.初始化值map对象 var compareMap = {}:// 定义全局变量 function initCompareMap(context){//context 为指定要初始化的区域,即上下文 ...

  5. php使用位与运算符【&】或【|】实现权限管理

    权限值是这样的2^0=1,相应2进数为”0001″(在这里^我表示成”次方”,即:2的0次方,下同)2^1=2,相应2进数为”0010″2^2=4,相应2进数为”0100″2^3=8,相应2进数为”1 ...

  6. 用scala实现一个sql执行引擎-(下)

    执行 上一篇讲述了如何通过scala提供的内置DSL支持,实现一个可以解析sql的解析器,这篇讲如何拿到了解析结果-AST以后,如何在数据上进行操作,得到我们想要的结果.之前说到,为什么选择scala ...

  7. 跟服务器交互的Web表单(form)

    使用HTML来构建可以跟服务器交互的Web表单(form),通过给你的form元素添加一个action属性来达到此目的. action属性的值指定了表单提交到服务器的地址. 例如: <form ...

  8. signalR制作微信墙 开源

    微信墙 上一篇文章中已经用PHP搭建了一个微信墙获取信息的服务器,我这里使用微软的signalr搭建一个客户端,signalr是一个为开发者开发实时应用的 一个库文件,支持windows server ...

  9. Asp.Net Web API 2第八课——Web API 2中的属性路由

    前言 阅读本文之前,您也可以到Asp.Net Web API 2 系列导航进行查看 http://www.cnblogs.com/aehyok/p/3446289.html 路由就是Web API如何 ...

  10. 在服务器端将现有Git项目导入GitLab

    GitLab是由Ruby语言开发的基于Linux的Git服务器,是我见过的最强大的Git服务器.发现它之后,立即决定将Git服务器换成GitLab. 但安装好GitLab之后面临一个问题,如何将服务器 ...