1

Salesforce 的专业版许可证不允许使用 APEX 代码或工作流,除非单独购买。

我需要清理 Salesforce 中通过我无法控制的 Web 表单输入的文本。客户想要修复所有大写或缺少句子大写的任何文本。

我在这个问题上看到了这个答案是否可以在 Salesforce 中为字段添加样式?它在自定义侧栏组件中使用 javascript。它假定当用户将数据键入应用程序时会发生转换。我的要求可能允许自定义 salesforce 按钮调用字段上的操作,因为数据将由自动化过程填充。

假设我要遵循相同的模式,我将不得不找到一种方法来可靠地检测和修复字符串中的错误格式。

有没有一种好方法可以在 salesforce 中使用 javascript 来做到这一点?

4

1 回答 1

2

由于正则表达式和 AJAX 工具包,我找到了一种更接近我需要的方法。

我创建了一个调用 javascript OnClick 的自定义详细信息按钮。

该代码采取当前领先并在字符类 [AZ] 中搜索“描述”字段以查找大于 2 个大写字符的任何字符串。每次它匹配一个字符串时,它都会用它自己的小写版本替换该字符串。

一旦字符串被“清理”,就可以更新线索。

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")} //adds the proper code for inclusion of AJAX toolkit
var url = parent.location.href; //string for the URL of the current page

var updateRecords = []; //array for holding records that this code will ultimately updated

  var re = new RegExp('[A-Z]{2,}', 'g');
  var inputString = "{!Lead.Description}";
  var matches = inputString.match(re);
  if(matches != null){
   for(var i = 0; i< matches.length;i++){
    inputString = inputString.replace(matches[i], matches[i].toLowerCase());
   }

  var update_Lead = new sforce.SObject("Lead"); //create a new sObject for storing updated record details
  update_Lead.Id ="{!Lead.Id}"; //set the Id of the selected Lead record
  update_Lead.Description = inputString;
  updateRecords.push(update_Lead); //add the updated record to our array

 }
 result = sforce.connection.update(updateRecords); //push the updated records back to Salesforce
 parent.location.href = url; //refresh the page

我将此代码基于我发现的一些Salesforce:执行 JavaScript 的自定义按钮

应该可以修改此代码以处理任何 Salesforce 对象并处理选择的字段。可以将进行替换的代码移到一个函数中以使其更容易。

于 2012-05-28T16:03:08.690 回答