Loading
通过单击(而不是节点)展开 Salesforce
用作特定于对象自定义操作的 Visualforce 页面

用作特定于对象自定义操作的 Visualforce 页面

对于作为自定义操作在对象上添加的 Visualforce 页面,将在该对象类型的记录上下文中调用。自定义操作会传输特定记录 ID — 用户单击自定义操作时查找的记录。设计在特定记录类型上操作的页面。

所需的 Edition

适用于 Salesforce Classic 和 Lightning Experience
适用于:GroupProfessionalEnterprisePerformanceUnlimitedContact ManagerDatabase.comDeveloper 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;"/>&nbsp;&nbsp;&nbsp;
                    <div>Contact:&nbsp;</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:&nbsp;</div><apex:inputField value="{!theCase.status}" />&nbsp;&nbsp;&nbsp; 
                    <div>Priority:&nbsp;</div><apex:inputField value="{!theCase.priority}" />&nbsp;&nbsp;&nbsp; 
                    <div>Case Origin:&nbsp;</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>
备注
备注 在您重定向到贵组织内部的 URL 时,操作对话框将在完成或以编程方式导航离开时关闭。如果您设置重定向以指向外部 URL,行为会因在新浏览器标签页中打开外部 URL 而异。

刷新主机页面的要求

如果您想要特定于对象或全局自定义操作刷新托管页面上的摘要,您创建用作此操作的 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 页面中指定自己的按钮时。
 
正在加载
Salesforce Help | Article