0

我可以使用 Visualforce 来编辑 salesforce/visualforce 页面的默认布局吗?

最终目标是修改 Edit 和 New 操作的默认布局,以从外部 API 对某些字段添加某种自动完成功能。

我希望能够添加我的 javascript 代码,而无需完全重写 visualforce 页面。

4

1 回答 1

1

您可以在主页组件中添加以下 jQuery。打开一个新的帐户页面并在发货国家或账单国家字段中输入一些内容,您将自动完成。在下面的脚本中,我有一个国家/地区的静态数组,您可以通过与外部服务器集成来使其动态化。

步骤:
1) 创建一个 HTML 区域和窄部分类型的主页组件,并添加以下脚本。
2)将主页组件添加到主页布局中。
3)确保选中“在所有页面上显示自定义侧边栏组件”(设置->应用程序设置->用户界面)选项。
4) 单击一个新帐户并输入“In”,您会发现自动完成功能正在运行。

<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css"/>
<script type="text/javascript">
    /*Create a new variable j$ just to avoid any conflicts with other libraries which may be using $.*/
    var j$ = jQuery.noConflict();
    /*Capture the list of countries in a Array.*/
    var countryArray = ['India', 'USA', 'China','FInland','Norway','Netherlands','England','Ukraine','Russia','Japan','Korea','Burma','Srilanka','Iran','Iceland','Canada','Rome','Australia','Armenia','Albania','Afghanisthan'];
    /*on Document ready*/
    j$(document).ready(function(){
        j$("#acc18country, #acc17country").autocomplete({
            source : countryArray
        });
    });
</script>  

在此处输入图像描述

希望这个“技巧”对你有用!
PS:如果您使用的是 google chrome 浏览器,那么第一次可能无法正常工作。加载页面时,您可能会在地址栏右侧看到一个灰色盾牌,单击它并选择“加载不安全的javascript”。为此,请在静态资源中添加 javascript 和 css 文件,然后在您的脚本标签中引用它们。

编辑:
现在要从外部 API 中提取数据,您应该添加以下代码。

<script src="/soap/ajax/26.0/connection.js" type="text/javascript"></script>    
var sid = getCookie('sid'); /*get the session ID cookie*/
var server = "https://" + window.location.host + "/services/Soap/u/26.0";
sforce.connection.init(sid, server);/*Initialize the sforce connection*/
sforce.connection.remoteFunction({
    url: "https://api.github.com/user/",
    requestHeaders: {"Content-Type":"application/json"}
    onSuccess : function(response) {
                      console.log('The response is ' +JSON.stringify(response));
              },
    onFailure : function(response) {
                      console.log("The request Failed with error: " + response)
}); 

但是,在发出此请求之前,请确保在远程站点设置(设置->管理员->安全控制->远程站点设置)中添加外部 API(https://api.github.com

于 2013-07-05T17:25:08.927 回答