The post Hide Edit/Del Links on Salesforce Standard Page appeared first on Justin Silver.
]]>It is not possible to control the visibility of the Edit/Del action links for a related list. On a VisualForce page you can insert your own CSS or Javascript to control the display, which you can also do on a Salesforce standard layout, albeit in a slightly more complicated fashion.
The trick is to use a Custom Link on your Home Page Layout. This Custom Link is defined as an onClick, but will actually load code inline with the use of REQUIRESCRIPT. Inside the REQUIRESCRIPT will be our Javascript payload, Base64 encoded.
First let’s compile the Javascript we need to control the UI on standard page layouts. In this case we want to hide the Edit/Del links on a related list, so view the page and use your developer tools to look at the DOM. You want to find the ID of the top level element in the related list table, something like “500c0000004BtmN_00sE0000004gkgq_body”. Use the following snippet as an example.
jQuery(document).ready(function($){
// hide this sidebar module
$('#sidebarDiv div.linksModule').each(function(){
var $module = $(this);
if ( $module.find('.brandPrimaryFgr').text()=='UserInterfaceInjection'){
$module.hide();
return false;
}
});
// hide the Edit/Del links
jQuery('#500c0000004BtmN_00sE0000004gkgq_body .actionColumn').hide();
});
Now we need to convert this to Base64. Any way is fine, but online is pretty easy: https://www.base64encode.org/.
alF1ZXJ5KGRvY3VtZW50KS5yZWFkeShmdW5jdGlvbigkKXsNCgkvLyBoaWRlIHRoaXMgc2lkZWJhciBtb2R1bGUNCgkkKCcjc2lkZWJhckRpdiBkaXYubGlua3NNb2R1bGUnKS5lYWNoKGZ1bmN0aW9uKCl7DQoJCXZhciAkbW9kdWxlID0gJCh0aGlzKTsNCgkJaWYgKCAkbW9kdWxlLmZpbmQoJy5icmFuZFByaW1hcnlGZ3InKS50ZXh0KCk9PSdVc2VySW50ZXJmYWNlSW5qZWN0aW9uJyl7DQoJCQkkbW9kdWxlLmhpZGUoKTsNCgkJCXJldHVybiBmYWxzZTsNCgkJfQ0KCX0pOw0KCS8vIGhpZGUgdGhlIEVkaXQvRGVsIGxpbmtzDQoJalF1ZXJ5KCcjNTAwYzAwMDAwMDRCdG1OXzAwc0UwMDAwMDA0Z2tncV9ib2R5IC5hY3Rpb25Db2x1bW4nKS5oaWRlKCk7DQp9KTs=
Put this text aside, we will need it later when creating the Javascript link.
Visit Setup > Home > Customize > Custom Links
UserInterfaceInjectionExecute JavascriptonClick Javascript{!REQUIRESCRIPT('data:application/javascript;base64,BASE64_JS')}, except that you want to replace BASE64_JS with your Base64 encoded Javascript.
Visit Setup > Home > Home Page Components
UserInterfaceInjectionLinksUserInterfaceInjection LinkVisit Setup > Home > Home Page Layouts
UserInterfaceInjectionNow when you visit your page the Action column should be hidden from your related list. It’s pretty easy to see how this could be further expanded to add all kinds of custom functionality to standard Page Layouts in Salesforce.
The post Hide Edit/Del Links on Salesforce Standard Page appeared first on Justin Silver.
]]>