4

I have been trying to figure out how I can make the "Send Notification Email" checkbox checked by default when changing the owner of a Case record in Salesforce. I know that you can toggle this from within the Case page layout editing screen, however there is a flaw with this option. It will default the checkbox to checked when you initially go to change an owner of a Case, however if you change the owner type to "Queue", the checkbox is immediately unchecked again. This is causing issues for us because our Support team are not realizing that the box is being unchecked when changing the owner type, so the notification is not getting sent.

I have attempted to correct this by adding some javascript to this page in the form of a Home Page Component, although I can only get it to act like Salesforce's flawed system where it will not stay checked once you change the owner type. Here is my javascript code.

window.onload = function()
{
if(window.location.href.indexOf('/500') != -1 && document.getElementById('sendMail'))
{
    document.getElementById("sendMail").checked = true;
};
};

Is there something I can add to this code to keep the checkbox checked when the owner type is modified? I also want to keep the ability of unchecking the box as well, but I want the Support user to have to manually uncheck the box since it would always be checked by default.


This is the final version of the code which works perfectly for defaulting the "Send Notification Email" checkbox to checked.

<script type="text/javascript">var originalOnLoad = window.onload;
window.onload = workaround;

function workaround(){
originalOnLoad();

document.getElementById("notifier").parentNode.parentNode.style.display = "none";
if (window.location.href.indexOf('/500') != -1 && document.getElementById('sendMail')) {
document.getElementById("sendMail").checked = true;
var ele = document.getElementById("newOwn_mlktp");
ele.addEventListener("change", checkSendEmail, false);
}
};

function checkSendEmail() {
document.getElementById("sendMail").checked = true;
}</script>
<a id="notifier"></a>
2
  • I extended your final version of this to include Mass Change Owner from a List View by including window.location.href.indexOf('CaseMassAction') in the condition. – AlwaysThinkin Feb 10 '14 at 20:26
  • Hi, I went ahead added this component to the Home Page Layout. But i do not see the Email notification checkbox being checked by default. What am i doing wrong ? Also, if I wanted to do same for other Objects - do i just change the KeyPrefix on this code from '/500' to '/Object#' ? – Amit Aug 18 '16 at 17:11
2

Try this out:

<script type="text/javascript">
window.onload = function ()
{
if (window.location.href.indexOf('/500') != -1 && document.getElementById('sendMail'))
{
    document.getElementById("sendMail").checked = true;
    var ele = document.getElementById("newOwn_mlktp");
    ele.addEventListener("change", checkSendEmail, false);
}
};

function checkSendEmail()
{

document.getElementById("sendMail").checked = true;

}
</script>
5
  • This worked perfectly, thanks! I do have one remaining question though. When I add this Home Page Component it is now showing up on the left-hand panel with the component name displaying and a blank box underneath it. Is there a way to make this component hidden so that it won't display anything since this is only javascript code? Also, when I go to edit this component it always puts "<br>" at the beginning of the code every time I re-save it. This could be the reason it is showing up in the left-hand panel. – Brandon May 31 '13 at 15:25
  • With the help of my brother I was able to figure this out. We added "document.getElementById("case-notifier").parentNode.parentNode.style.display = "none";" before the IF statement, and then added "<a id="case-notifier"></a>" after the closing Script tag. This now hides the component. Thanks again for the help! – Brandon May 31 '13 at 20:54
  • I have slightly modified the code as it was causing an issue where Salesforce's standard onload method wasn't loading at all which resulted in the help text bubbles to not function correctly as well as a few other random glitches. I added the finished code above to the original post. – Brandon Jun 4 '13 at 16:35
  • It doesn't work at my end. I did a lot of debugging but still unable to find out the exact reason for the same. While debugging I found one onchange function while changing the dropdown of Case Owner and if we can add a condition below then it will work fine. But I am still not getting how I am going to append it to the Case ownership page. Please suggest. LookupAutoCompleteInputElement.handleLookupTypeChange('newOwn',false);if (getElementById('newOwn_lktp').value.search('queue') < 0 && true) { getElementByIdCS('sendMail').checked = true; } else { getElementByIdCS('sendMail').checked = false; – user4040 Oct 7 '13 at 22:02
  • You can append this to the Case Change Ownership Page by adding the JavaScript as a "HTML Area" Home Page Component and including it in the Home Page Layouts on the Narrow (Left) Component section. Worth noting that if you don't use the final version which protects the original page load from being overridden, in addition to losing help bubbles, you also lose the Related List links above the Detail sections. – AlwaysThinkin Feb 7 '14 at 19:18
1

For making Send Notification Email checkbox as true, we can create a custom formula field in object and can remove the standard Owner field from the Page Layout. This custom field will work same as standard field.

Follow the given steps to create custom field in object -

  • Select the object in which you want the Send Notification Email checkbox as true.
  • In Custom fields and Relationships, click New for creating new custom field.
  • Select Formula as Data Type
  • Put Owner in Field Label and same in Field Name
  • Select Text as Formula Return Type
  • Put the given text in Formula Editor

    HYPERLINK('/'+OwnerId , Owner.FirstName+' '+Owner.LastName ,Owner.FirstName) +' '+ HYPERLINK('/'+Id+'/a?retURL=%2F'+Id+'&sendMail=1','[Change]','Change')

  • Click Next and then Save the field

1

I think no need any script to check 'Send Email Notification' check box by default. Salesforce providing facility to check this check box by default. Use below navigation to achieve this.

Setup--> App Setup--> Customize--> Cases--> Support Settings--> Enable 'Notify Case Owners when Case Ownership Changes' check box.

0

solution did not work for me. Did not hide the component or keep the email notification checked when assigning a case to a queue

1
  • 1
    Petyr, which answer where you trying to comment on ? – Samuel De Rycke Mar 23 '15 at 23:01
0

With the use of formula fields it can be achieved:

  1. Create a formula field called "Owner" with data type as "Text".

Use this code if the Object has owner and queue

HYPERLINK('/'+ IF(ISBLANK(Owner:Queue.QueueName),OwnerId,'p/own/Queue/d?id=' + Owner:Queue.Id ), 
IF(ISBLANK(Owner:Queue.QueueName), 
Owner:User.FirstName +' '+Owner:User.LastName,Owner:Queue.QueueName) ,
IF(ISBLANK(Owner:Queue.QueueName),Owner:User.FirstName, Owner:Queue.Id )
) 
+' '+ HYPERLINK('/'+Id+'/a?retURL=%2F'+Id+'&sendMail=1','[Change]','Change')

If Object doesn't have queue, then use this:

HYPERLINK('/'+OwnerId ,  Owner:User.FirstName +' '+Owner:User.LastName ,Owner:User.FirstName) 
+' '+ HYPERLINK('/'+Id+'/a?retURL=%2F'+Id+'&sendMail=1',
'[Change]','Change')
  1. Replace the default owner field with this custom field in page layout and use proper permissions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.