【问题标题】:How to clean up text fields in Salesforce without using APEX or Workflow如何在不使用 APEX 或 Workflow 的情况下清理 Salesforce 中的文本字段
【发布时间】:2012-05-29 15:46:30
【问题描述】:

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

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

我在这个问题Is it possible to add style to a field in Salesforce? 上看到了这个答案,它在自定义侧栏组件中使用了 javascript。它假定当用户将数据键入应用程序时会发生转换。我的要求可能允许自定义 salesforce 按钮调用字段上的操作,因为数据将由自动化流程填充。

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

有没有在 salesforce 中使用 javascript 的好方法?

【问题讨论】:

    标签: javascript salesforce


    【解决方案1】:

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

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

    代码在字符类 [A-Z] 中搜索“描述”字段以查找任何大于 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: Custom Button to Execute JavaScript

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-24
      • 2013-07-20
      • 1970-01-01
      • 2021-04-25
      • 2015-06-26
      • 1970-01-01
      相关资源
      最近更新 更多