用作特定于对象自定义操作的 Visualforce 页面
对于作为自定义操作在对象上添加的 Visualforce 页面,将在该对象类型的记录上下文中调用。自定义操作会传输特定记录 ID — 用户单击自定义操作时查找的记录。设计在特定记录类型上操作的页面。
所需的 Edition
| 适用于 Salesforce Classic 和 Lightning Experience |
| 适用于:Group、Professional、Enterprise、Performance、Unlimited、Contact Manager、Database.com 和 Developer Edition |
创建用作特定于对象操作的 Visualforce 页面必须使用标准对象控制器。使用控制器扩展来添加自定义代码,包括您可以使用 JavaScript 远程调用的@RemoteAction方法。
您的自定义代码不仅仅可用于更新原始记录。例如,“创建快速订单”自定义操作搜索匹配的商品。然后,该操作可以创建发票和行式项目,均作为创建部分订单的一部分。该逻辑在原始客户记录的上下文中发生 - 该发票与调用快速订单操作的客户记录相关。
下列代码示例显示设计用于在客户对象上作为自定义操作的页面,因此它使用标准客户控制器。此操作让用户从客户详细信息页面创建个案,它与标准创建操作的用户界面不同。
public with sharing class CreateCaseExtension {
private final SObject parent;
public Case theCase {get; set;}
public String lastError {get; set;}
public CreateCaseExtension2(ApexPages.StandardController controller) {
parent = controller.getRecord();
theCase = new Case();
theCase.accountId = parent.id;
lastError = '';
}
public PageReference createCase() {
createNewCase();
theCase = new Case();
theCase.accountId = parent.id;
return null;
}
private void createNewCase() {
try {
insert theCase;
FeedItem post = new FeedItem();
post.ParentId = ApexPages.currentPage().getParameters().get('id');
post.Body = 'created a case';
post.type = 'LinkPost';
post.LinkUrl = '/' + theCase.id;
post.Title = theCase.Subject;
insert post;
} catch(System.Exception ex){
lastError = ex.getMessage();
}
}
}
<apex:page standardcontroller="Account" extensions="CreateCaseExtension" showHeader="false">
<script type='text/javascript' src='/canvas/sdk/js/publisher.js'/>
<style>
.requiredInput .requiredBlock, .requiredBlock {background-color: white;}
.custompubblock div {display: inline-block;}
.custompublabel {width:54px;}
</style>
<script>
function refreshFeed() {
Sfdc.canvas.publisher.publish({name : 'publisher.refresh', payload : {feed:true}});
}
</script>
<div>
<apex:form >
<apex:actionFunction action="{!createCase}" name="createCase" rerender="out"
oncomplete="refreshFeed();"/>
<apex:outputPanel id="out" >
<div class="custompubblock">
<div class="custompublabel">Account:</div><apex:inputField value="{!theCase.accountId}"
style="margin-left:0;"/>
<div>Contact: </div><apex:inputField value="{!theCase.contactId}" />
</div>
<apex:inputField value="{!theCase.description}" style="width:538px;height:92px;margin-top:4px;" />
<div class="custompubblock" style="margin-top:5px;">
<div>Status: </div><apex:inputField value="{!theCase.status}" />
<div>Priority: </div><apex:inputField value="{!theCase.priority}" />
<div>Case Origin: </div><apex:inputField value="{!theCase.origin}" />
</div>
</apex:outputPanel>
</apex:form><br/>
<button type="button" onclick="createCase();"
style="position:fixed;bottom:0px;right:0px;padding:5px 10px;
font-size:13px; font-weight:bold; line-height:
18px;background-color:#0271BF;background-image:-moz-linear-gradient(#2DADDC, #0271BF);background-repeat:repeat-x;border-color:#096EB3;"
id="addcasebutton">Create Case</button>
</div>
</apex:page>
刷新主机页面的要求
如果您想要特定于对象或全局自定义操作刷新托管页面上的摘要,您创建用作此操作的 Visualforce 页面必须:
- 引用发布者 JavaScript 文件:
<script type='text/javascript' src='/canvas/sdk/js/publisher.js'/>.(创建自定义 Visualforce 操作不需要画布 SDK。) - 包括此 JavaScript 调用:
Sfdc.canvas.publisher.publish({name : 'publisher.refresh', payload : {feed:true}});.
- 用作全局自定义操作的 Visualforce 页面
Visualforce 用作全局操作的 Visualforce 页面可在多个不同位置中调用,且没有与其关联的特定记录。它们有完全的操作自由,这意味着由您来写代码。 - 隐藏 Visualforce 自定义操作的操作标题
创建要作为自定义操作使用的 Visualforce 页面时,您可以选择隐藏操作标题。隐藏操作标题有助于防止用户困扰,尤其您已在 Visualforce 页面中指定自己的按钮时。
本文章是否解决您的问题?
请与我们共享您的想法,以便我们进行改进!

