第二篇:salesforce自定义link/button并执行js
来源:互联网 发布:南京行知基地 编辑:程序博客网 时间:2024/06/08 05:47
场景:当记录被锁定(因为审批操作而锁定)后,非超级管理员不能通connection.js的如下方式更新字段:
{!REQUIRESCRIPT("/soap/ajax/40.0/connection.js")}alert('确认后,该项目将发布至项目比选平台!');var tp = new sforce.SObject('Tender_Project__c');tp.id = "{!Tender_Project__c.Id}";tp.isPublished__c = true;tp.Compare_Stage__c = '比选应标';var result = sforce.connection.update([tp]);if(result[0].getBoolean("success")) { alert('发布成功!'); window.location.reload();}else { alert('网络异常,请尝试重新发送,仍然出现请联系系统管理员!');}
{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")} //adds the proper code for inclusion of AJAX toolkitvar url = parent.location.href; //string for the URL of the current pagevar records = {!GETRECORDIDS($ObjectType.Lead)}; //grabs the Lead records that the user is requesting to updatevar updateRecords = []; //array for holding records that this code will ultimately updateif (records[0] == null) { //if the button was clicked but there was no record selectedalert("Please select at least one record to update."); //alert the user that they didn't make a selection } else { //otherwise, there was a record selectionfor (var a=0; a<records.length; a++) { //for all recordsvar update_Lead = new sforce.SObject("Lead"); //create a new sObject for storing updated record detailsupdate_Lead.Id = records[a]; //set the Id of the selected Lead recordupdate_Lead.Status = "Unqualified"; //set the value for Status to 'Unqualified'updateRecords.push(update_Lead); //add the updated record to our array}result = sforce.connection.update(updateRecords); //push the updated records back to Salesforceparent.location.href = url; //refresh the page}
现状:超级管理员的身份能点击按钮更新字段,没有那么高权限的专员点击按钮不能更新,并提示错误信息。
错误信息:{errors:{message:'此记录已锁定。如果您需要编辑,请联系您的管理员。', statusCode:'ENTITY_IS_LOCKED', }, id:null, success:'false', }
workaround:使用webservices,通过call apex来提高系统用户的权限。
步骤:
1、编写webservice类:
global class UpdateStateByCustomButtonFunction { webservice static String updateState(ID recId){ String errMsg = '发布成功!'; Tender_Project__c tp = new Tender_Project__c(); tp.Id = recId; tp.Is_Published__c = true; try{ update tp; }catch(DmlException e) { System.debug('update error: '+e.getMessage()); errMsg = '网络异常,请尝试重新发送,仍然出现请联系系统管理员!'; }return errMsg;}}2、添加该类到相关操作专员简档,允许专员访问该apex类;
3、编写js逻辑:
{!REQUIRESCRIPT("/soap/ajax/40.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/40.0/apex.js")} alert('确认后,该项目将发布至项目比选平台!'); var result = sforce.apex.execute("UpdateStateByCustomButtonFunction","updateState",{recId:"{!Tender_Project__c.Id}"});//类名,方法名,参数 if(result = '发布成功!') { alert(result); location.reload(); }else { alert('网络异常,请尝试重新发送,仍然出现请联系系统管理员!') }
参考资源:
http://www.mstsolutions.com/blog/content/creating-custom-button-javascript-salesforce
http://blog.shivanathd.com/2014/07/call-apex-class-from-custom-button-salesforce.html
问题2:在记录锁定的情况下,通过自定义button,输入并更新记录的某一字段?
solution:在alert中输入值,并利用ajax更新字段。
preview:
资源链接:
https://www.ebsta.com/blog/custom-buttons-in-salesforce/
http://www.jitendrazaa.com/blog/salesforce/create-and-update-records-using-javascript-button-in-salesforce-ajax-toolkit/
- 第二篇:salesforce自定义link/button并执行js
- salesforce中自定义button执行js调用后台apex代码
- JS学习第二篇;自定义事件并监听
- JS执行link
- Salesforce 自定义页面并实现手机端自适应
- 服务器Button执行js方法
- 代码自定义cell 并添加button响应
- salesforce自定义按钮使用js与后台交互demo/自定义按钮跳转至指定URL
- Link button in wpf
- Salesforce -- 自定义放大镜查找界面
- 异步加载js并执行js方法
- iOS自定义相机中的button点击方法不执行
- UITableView增加自定义Button并绑定点击事件
- 使用js为button添加回车执行事件
- js link
- 自定义button
- 自定义BUTTON!
- 自定义button
- 数据结构之树的存储结构
- Google map 搜索+点击地图添加标注点 并且返回坐标
- SQLServer服务器数据库之间的数据操作(完整版)
- Linux网络编程/poll服务器
- Leetcode 357. Count Numbers with Unique Digits
- 第二篇:salesforce自定义link/button并执行js
- php组合模式
- idea从svn中导入多模块项目
- viewPager fragment 懒加载
- ZXing二维码扫描
- for简单小训练
- [BZOJ]4491: 我也不知道题目名字是什么 线段树(差分)
- oracle 获取年月
- QT常用控件之QVBoxLayout,QRadioButton,QCheckBox,QMenu,QAction