【平台特性】:在Salesforce中,标准页面上的审批历史相关列表上的 提交审批按钮不能通过配置的方式移除。
基于前面的介绍,我们会面临一个尴尬的问题:自定义按钮展示在Detail页面上,辨准按钮展示在Related List页面上,一旦用户点击了Related List上的按钮,那这个自定义按钮放在上面就显得自欺欺人了。
【How to do? - 套路】
通常我们会通过将审批初始提交人设为超级管理员或加一个checkbox控制准入条件,这样业务人员不管在什么条件下点击了Related List上的按钮都会进入到无效的访问权限页面。
使用checkbox方法思路:
a、新建checkbox字段(是否为标准审批按钮),默认unchecked;- 若默认为checked,那历史数据不会勾上。
b、配置准入条件,该字段为true,才允许进入;
c、代码中设置req.setSkipEntryCriteria(true),用来跳过进入条件即可。
更新:by180511,上面套路太low了,直接用公式将准入条件变为false即可,如下:
1、自定义一个VF页面(仅仅包含批准历史相关列表),然后在VF里面使用Js Hack去隐藏按钮;
【效果Preview】:
【Step by Step】:
a、开发VF logic code:
<apex:page standardController="ApprovalTest__c"> <script src="https://code.jquery.com/jquery-2.x-git.min.js"></script> <script> $j = jQuery.noConflict(); console.log(window.location.href); console.log(window.location.href.indexOf(".com/a0C")); console.log(window.location.href.indexOf(".com/a0C") != -1); if(window.location.href.indexOf(".com/a0C") == -1) { $j(document).ready(function() { $j("input[name='piSubmit']").hide(); }); } </script> <apex:relatedList list="ProcessSteps" id="customApprovalList"></apex:relatedList> </apex:page>b、将页面VF加入页面布局:
之后,you make it.
2、在Home Page的sidebar中注入Js,通过Js hack的方式隐藏Related List上的提交审批按钮;
I have already gone through solution here Display "Submit for Approval" button in the Approval History related list based on condition but since new release summer 15 home page component no more supports JS , so that does not worked for me.
看到上面一句话不禁有些伤心,summer 15之后不能在html类型的home component中加js。
a、自定义injection Custom Links;- 注意静态资源的引用
{!REQUIRESCRIPT("/resource/1402932484000/JQuery320")} $j = jQuery.noConflict(); if(window.location.href.indexOf(".com/a0C") != -1) { $j(document).ready(function() { $j("input[name='piSubmit']").hide(); $j(".relatedProcessHistory .pbHeader h3").css('padding', '8px 0'); }); }
b、在自定义Link类型主页组件里添加injection custom link;
c、在主页布局中启用injection-box自定义组件。
【效果preview】:
最终你会发现,这种方式你需要点击sidebar自定义链接后才能实现隐藏的效果。
3、通过在VF类型home page component中加入js代码,不可行。原因:不能快iframe操作dom。
【总结】:首推配置的方式,其次是方法1。
参考资料:
https://salesforce.stackexchange.com/questions/38918/end-of-javascript-sidebar-workarounds-salesforce-classic-aloha#comment144978_98915
https://help.salesforce.com/articleView?d=70130000000NIyh&eid=singlesend&id=Message-Alerts-and-Custom-Links-Home-Page-Components-changes&language=en_US&type=1