How to override the “Send an Email” button on the Case object – Emails related list

On the Case object page, there is an Emails related list which has a Send an Email button taking the user to another page to fill in the email.

I haven’t been able to find a way to override the functionality of this Send an Email button, or customise the Emails related list in any way. All I want to do is to manipulate the URL onclick so that the p26 parameter is set which will set the email From: address to a certain value.

I have done this by creating a custom Send an Email button and adding it to the Case page, but the Send an Email button on the Emails related list is still there of course, so if users press that one then they don’t get the custom functionality.

Is there anyway I can override the default functionality, or remove the standard Send an Email button?

Thanks

Answer

In order to change the link URL for the New Email button, you have to use a Javascript hack. Create a new “narrow” Homepage Component (really a Sidebar component, but SFDC calls them Homepage components) and paste the following code in (be sure to check off Show HTML first, so that this is entered as code, not as text)

<div id="remove-shortcut-id">
Click "Show HTML" to see hidden javascript code.<br/>
<b>DO NOT SAVE UNLESS JAVASCRIPT IS VISIBLE</b> or else that code will be erased.
</div>

<script type="text/javascript"><!--
function changeNewEmailQuery() {
    var PARAMETERS_TO_ADD = 'p26=add_it_here&other=if_another_one';
    var cid = window.location.pathname.replace('\/', '');
    if (cid.indexOf('500') != 0) return;
    var newEmailBtn = document.getElementsByName("newEmail");
    if (newEmailBtn[0] && newEmailBtn[0].query_fixed == false) {
        var btn = newEmailBtn[0];
        var fn = btn.onclick.toString()
        var navUrl = fn.match(/navigateToUrl\('([^']*)'.*/)[1];
        navUrl = navUrl + "&" + PARAMETERS_TO_ADD;
        btn.onclick = function (event) { navigateToUrl(navUrl, null, 'newEmail'); };
        btn.query_fixed = true;
    }
}
/* Run immediately on page load and queue for second run after related lists load */
changeNewEmailQuery();
setTimeout('changeNewEmailQuery();', 100);
/* hide this component */
document.getElementById('remove-shortcut-id').parentElement.style.display = 'none';
--></script>

Save this component and add it to your Homepage layout as a narrow column. The code will run on each page load, and whenever it sees the NewEmail, it will edit the query string.

(Fixed doublequote issue)

Attribution
Source : Link , Question Author : Joe , Answer Author : collymitch

Leave a Comment