Use Case

In Salesforce, when you click on the standard ‘New’ button on a Related List to create a new record on the child object from the record currently in context in a Detail Page, after you click ‘Save’ and save the new record, it returns you to the Detail Page for the newly created record by default. For parent-child object relationships that have high levels of data entry on the child object, this creates a user experience issue as the user will have to click on the link to the parent record in order to return to the Detail Page to continue adding child records or perform additional functions on the parent record.

Solution

The concept behind the solution is straightforward enough, but there are some tricky potential “gotchas” in the implementation that we need to be mindful of. What we are going to do is create a new Custom Button on the child / target object to replace the standard ‘New’ button that gets displayed on a Related List when looking at the Detail Page of a parent record.

The first thing that we need to do is grab the ID of the Lookup field on the child object that represents either the Lookup or Master-Detail Relationship to the parent object. This is important, because we will need to include two URL parameters that provide the record ID of the parent record, otherwise the lookup field will have a blank value when we create a new child record using this new custom button; this would require the user to manually perform a lookup, which is self-defeating since the expected behavior when clicking a ‘New’ button on a related list is to have the parent record ID available in context to pre-populate the dependent field.

To do this, simply go to the Detail Page for a record on the parent object. Navigate to the related list for the child object (obviously you would need to add this if it didn’t already exist), and click the ‘New’ button.  Copy the URL of the new page that appears and paste it somewhere that can be referenced throughout this process. It should look something like this:

https://naX.salesforce.com/a00/e? CF00NE0000002UJYd=Name+of+Parent+Record &CF00NE0000002UJYd_lkid=a03E0000002255P &retURL=%2Fa03E0000002255P

Whoa! What does all of this mean?

  • naX.salesforce.com – This is the instance of Salesforce that you are currently working on.  An example could be ‘NA9′.
  • a00 – This is the ID of the object that we are creating a new record for.
  • e? – This simply means that we are editing a record.  Now the ‘?’ character is the important part – this means that there are some parameters being passed through in the URL, and that whatever follows the ‘?’ is a parameter, which in this case is…
  • CF00NE0000002UJYd=Name+of+Parent+Record - This just happens to be the first parameter that was appended to this URL…do not worry about the order in which parameters appear in the URL. But when we see something with the prefix ‘CF’, it means that this is a reference to a Custom Field. The next 15 characters are the ID of the custom field. All URL parameters follow a ‘Key=Value’ convention, so after the Key (CF00NE0000002UJYd) and the ’=’ character, we get a value that represents the Name of the parent record…this is important, because it represents the human-readable value that gets pre-populated into your lookup field on the child record. NOTE: The 15-character ID that follows ‘CF’ will be a different value than what we are using here as an example; it is a unique identifier for every Custom Field in your Salesforce org.
  • &CF00NE0000002UJYd_lkid=a03E0000002255P – This is the next URL parameter. How do we know this? The ‘&’ character is our clue. Just as the ‘?’ character means that parameters are included in the URL, the ‘&’ character tells us that there is more than one parameter, and what follows the ‘&’ character is another URL parameter. In this case, the Key is ‘CF00NE0000002UJYd_lkid’. Does this look at all familiar? That’s right, it’s very similar to our previous URL parameter in that it starts out with the ‘CF’ convention for a Custom Field, and it has the same 15-character string representing the ID of the Custom Field, but you’ll notice that ‘_lkid’ is appended to the end. This stands for ‘Lookup ID’ and the corresponding value is a 15-character string representing the Record ID of the parent record. Why do we need this? Well, we may already have the Name of the parent record, but providing the ID of the parent record ensures that no additional data entry is required by the user in order for the value of the Lookup field to reference the correct parent record.
  • &retURL=%2Fa03E0000002255P – Again the ‘&’ character simply tells us that another URL parameter follows; in this case we get a Key of ‘retURL’ which tells Salesforce where to redirect the user in the event that the function is cancelled, with the Value being ‘%2F’ (the URL-encoded value for a ‘/’ character) plus the record ID of the record that was in context when the ‘New’ button on the Related List was clicked.

What do we do with all of this? Well, here’s the interesting part – that URL in and of itself is sufficient for getting a user to a screen where they can enter data for a new child record, and if they click the ‘Cancel’ button, Salesforce will know to return them to the Detail Page of the record that they were viewing when they clicked the standard ‘New’ button. But that doesn’t solve our problem – we’re not looking to return to the Detail Page when clicking ‘Cancel’ per se, we’re more interested in returning to the parent record’s Detail Page after the user clicks ‘Save’ on the new record. This URL doesn’t do the trick for us, so we need to somehow have Salesforce follow a different one when a new record is created from a Related List. But how?

The trick is to create a new Custom Button on the child object using these options:

  • Label – Whatever text you want displayed on this new button. Give it a descriptive name like ‘New (insert child object name here).”
  • Name – Give it a unique name, using only alphanumeric characters and underscores…no spaces or consecutive underscores.
  • Description – Whatever you’d like.
  • Display Type – Select “List Button” because we will be adding this to a Related List.
  • Behavior  - “Display in existing window without sidebar or header”
  • Content Source – “URL”

Now here comes the fun part. We need to construct a formula that will return a URL that provides us with all of the functionality of the standard ‘New’ button, but includes a URL parameter that tells Salesforce to return the user to the Detail Page of the parent record after this new record is saved.

This formula will be based on the URLFOR function, and at a high level will look like this:

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

A specific example of the URLFOR function constructed to return a URL that provides us with everything we’re trying to accomplish here:

{!URLFOR( $Action.Child_Object_Name__c.New , null, [saveURL=Parent_Object_Name__c.Link, retURL=Parent_Object_Name__c.Link, CF00NE0000002aLV0_lkid=Parent_Object_Name__c.Id , CF00NE0000002aLV0=Parent_Object_Name__c.Name])}

  • target – This is where we want the user to end up when this hyperlink is clicked. In our case, we want to use $Action.Child_Object_Name__c.New, obviously changing ‘Child_Object_Name__c’ to the specific API name of your child object.
  • id – This is the ID of the record in context. This actually doesn’t pertain to us, because we’re creating a new record and will not have a record ID assigned until the record is saved. So in this case, let’s use ‘null‘ for the value of ‘id’.
  • inputs- Remember all of the URL parameters that we talked about above? Those go here using a Key = Value convention, with multiple items separated by commas. Don’t worry about not having the ‘?’ or ‘&’ characters in here, Salesforce will add them for you at runtime. So here are the URL parameters that we need:
    • saveURL=Parent_Object_Name__c.Link – Replace ‘Parent_Object_Name__c’ with the API name of your parent object. This parameter represents the secret sauce in everything we’re trying to accomplish – this is the URL that Salesforce will return the user to after the ‘Save’ button is clicked on the new record Edit Page.
    • retURL=Parent_Object_Name__c.Link - Replace ‘Parent_Object_Name__c’ with the API name of your parent object. This returns the user to a record Detail Page if the ‘Cancel’ button is pressed on the new record Edit Page.
    • CF00NE0000002aLV0_lkid=Parent_Object_Name__c.Id - Replace ‘Parent_Object_Name__c’ with the API name of your parent object, and replace the 15-character ID string contained in ‘CF00NE0000002aLV0_lkid’ with the ID of the Custom Field on the child object that looks up to the parent.
    • CF00NE0000002aLV0=Parent_Object_Name__c.Name - Replace ‘Parent_Object_Name__c’ with the API name of your parent object, and replace the 15-character ID string contained in ‘CF00NE0000002aLV0′ with the ID of the Custom Field on the child object that looks up to the parent.
  • no override – This is completely optional, and in fact we have left it out of our example. By default this is set to ‘false’, but if it were set to ‘true’ it would override any overrides that you may have in place for the ‘View’ for the record you are referencing in context.

Once you have this formula constructed, click on the ‘Check Syntax’ button. If there are errors, troubleshoot and correct them. If you get the “No syntax errors in merge fields or functions” all-clear, save this Custom Button and you’re almost done!

To get the Custom Button to appear on the Related List, edit the Page Layout(s) of the parent object.  Click on the little wrench that appears in the tab above the label of the Related List for the child object.  Expand the ‘Buttons’ section, uncheck the box next to the standard ‘New’ button, and under Custom Buttons, find your new button in the ‘Available Buttons’ section, click the ‘Add’ button (arrow facing right),  and your button should now appear under the ‘Selected Buttons’ section.  Click ‘OK’ and then save your Page Layout. Rinse and repeat for each Page Layout that needs to include this button in the Related List for the child object.

Test out your shiny new button by opening a record in the parent object, navigating down to the Related List for the child object, clicking on your custom ‘New’ button, and entering data into a new record for the child object…

  1. Does it take you back to the Detail Page for the correct record if you click ‘Cancel’?
  2. Is the correct record name populated in the Lookup field to the parent object?
  3. If you click ‘Save’ after entering data in the new record for the child object, does it take you back to the Detail Page of the parent record?
  4. Do you see the new record in the Related List for the child object?

[salesforce] standard button的更多相关文章

  1. 在Salesforce中可以对某一个Object的Standard Button或Link进行重写

    在Salesforce中可以对某一个Object的Standard Button或Link进行重写,来实现我们特定的逻辑过程,比如:在删除某个Object之前要判断该Object的某个Field的状态 ...

  2. wx.button

    wx.Button A button is a control that contains a text string, and is one of the most common elements ...

  3. BootStrap中的button使用

    原文地址:http://www.phloxblog.in/bootstrap-buttons/#.U5xYso2fclm 站点中事件的触发往往依赖于button或者超链接.因此,button能够觉得是 ...

  4. CSS 命名管理 之 BEM

    好吧,将 BEM 简单的解释为 “Block-Element-Modifier“, 其实是个不负责任的做法.鬼知道 Block 是什么啊?所以,看了一些似懂非懂的中文解释之后,自己还是得去找些英文来读 ...

  5. bootstrap学习总结-05 常用标签3

    1 单选框,多选框 1)单选框 单选框(radio)用于从多个选项中只选择一个.设置了 disabled 属性的单选或多选框都能被赋予合适的样式.对于和多选或单选框联合使用的 <label> ...

  6. 《深入理解bootstrap》读书笔记:第三章 CSS布局

    一. 概述一下理念 bootstrap基于H5开发.提倡移动先行(媒询声明是必须的),对浏览器支持面不是很广. 响应式图片:max-width:100% height:auto; 可以加上:.img- ...

  7. web前段 弹出小例子

    <html> <head> <meta charset="utf-8"> <meta name="viewport" ...

  8. CSS组件架构的设计思想

    不管是设计思想,还是架构,都可以总结为一个词:AO模式.A表示Append,即“附加”的意思,O表示Overwrite,即“重写”的意思.所有的CSS组件都是沿用这种思想来设计的.这也是CSS的特性, ...

  9. android:style.xml

    <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2006 The Andr ...

随机推荐

  1. centos6搭建VPN

    1,检查是否开启PPP #cat /dev/ppp cat: /dev/ppp: No such device or address //表示已经开启 2,安装ppp和iptables #yum in ...

  2. aceAdmin fuelux tree 从后台获取数据,并设置节点ID等属性

    如题,从后台封装数据,有两种方式渲染节点的数据: 1.全部节点加载 2.根据父节点加载子节点 首先,先介绍下第一种渲染方式: 后台返回数据格式(所有的附加属性,都可放在additionalParame ...

  3. Struts2的值栈和对象栈

    ValueStack 如何得到值栈: 如何将对象存入值栈: 让值栈执行表达式来获得值: 在JSP中跳过栈顶元素直接访问第二层: 在JSP中访问值栈对象本身(而不是它们的属性) ActionContex ...

  4. NSDate--日期格式

    日期格式: 年: y 将年份 (0-9) 显示为不带前导零的数字 yy 以带前导零的两位数字格式显示年份 yyy 以四位数字格式显示年份 yyyy 以四位数字格式显示年份 月: M 将月份显示为不带前 ...

  5. XML文件与实体类的互相转换

    XML文件与实体类的互相转换 一.将XML文件反序列化为实体类对象 1. 通常程序的配置信息都保存在程序或者网站的专门的配置文件中(App.config/web.config).但是现在为了演示XML ...

  6. Subsets 子集系列问题 leetcode

    子集系列问题: Coding 问题中有时会出现这样的问题:给定一个集合,求出这个集合所有的子集(所谓子集,就是包含原集合中的一部分元素的集合). 或者求出满足一定要求的子集,比如子集中元素总和为定值, ...

  7. html 问题

    1.footer处理 目标: 页面较短,footer位于页面底部,出现滚动条时,依然在原来的位置,不随滚动条移动 页面较长,位于元素底部 .container{ position: relative ...

  8. ASP.NET Core 源码阅读笔记(5) ---Microsoft.AspNetCore.Routing路由

    这篇随笔讲讲路由功能,主要内容在项目Microsoft.AspNetCore.Routing中,可以在GitHub上找到,Routing项目地址. 路由功能是大家都很熟悉的功能,使用起来也十分简单,从 ...

  9. 360浏览器下jquery.validate.unobtrusive的日期验证问题

    今天在招聘频道(job.cnblogs.com)遭遇这样一个问题——在360浏览器下,在一个表单验证中,虽然输入了有效的日期,却总是提示日期格式错误,见下图: 而在Chrome/Safari/Fire ...

  10. 分享我用Qt开发的应用程序【二】在Qt应用程序中使用字体图标fontawesome

    为了使用简单,需要先写一个单件类,头文件的代码如下: 其中静态方法Instance保证IconHelper的实例全局唯一 (注意构造函数已经私有化了) #ifndefICONHELPER_H #def ...