7

I am trying to determine if it is possible to suppress the Case Assignment Notification email from within a Before Update Trigger. Or confirm that this is a newly introduced bug since I believe I was able to do this prior to Summer12.

Basic requirement: if a User manipulates the Case Status set that user to the Owner of the Case.

The email notification is unnecessary since the User knows that changing the Status makes them the case owner.

I've tried

  • setting DMLOptions per Case sObject using SetOptions()
  • calling Database.Update(..,..) with the DMLOptions

Nothing appears to allow me to suppress that "Send Email Notification" email when the OwnerId is updated programmatically. On the Change Case Owner Screen, this option is a checkbox and is obeyed faithfully by selecting it prior to hitting save.

And now some code:

    for(Case c : [Select Id,ownerId,status from Case where Id in :caseIds])
    {
        if(c.Status=='Initial')
        {
            c.ownerId = system.Userinfo.getUserId();

            //THIS DMLOPTION SEEMS TO BE IGNORED IN BEFORE UPDATE TRIGGERS
            Database.DMLOptions dlo = new Database.DMLOptions();
            dlo.EmailHeader.triggerAutoResponseEmail = false;
            dlo.EmailHeader.triggerUserEmail = false;
            c.SetOptions(dlo); 


            casesList.add(c);
        }

    }
update casesList;

Does anyone know of any creative workarounds for suppressing the Case Assignment Notification email??

4

I thought I'd add this as a separate answer:

If you go to

Setup -> Customize -> Cases -> Support Settings

there is an option near the bottom marked

"Notify Case Owners when Case Ownership Changes" - Use this setting to automatically select the Send Notification Email checkbox on cases when users change a case owner to another user.

UPDATE: - To stop only Apex changes sending Email:

  1. Disable this option (So all emails)
  2. Add a custom boolean field added to the Case object - default: False
  3. Setup a workflow that sends an email on Case Ownership changes only if the custom boolean field is False

Before Updating in Apex set the boolean field to True, run your update then reset the boolean field to False

This will allow you to block the email wherever you need in your Apex

4
  • Yes, unfortunately this setting would turn off ALL EMAILS when the Case Ownership changes and I am only looking to prevent the Notification Email when the Case Ownership is changed programmatically (in Apex). I'm beginning to believe this is either a new bug or there is no way to suppress this email on a case-by-case ownership change. – B3Million Aug 16 '12 at 18:33
  • Hmm a more long winded approach might be to disable this option (So all emails), then setup a workflow that sends an email on Case Ownership changes, but have a custom boolean field added to the Case object that the Worflow checks. You could then set / unset this boolean before & after your Ownership in Apex. This would allow you to block the email in the instances you wanted. – Jon Hazan Aug 17 '12 at 9:03
  • Hey Jon, I'll take this as the "Accepted Answer" since this is the best alternative approach I've heard. Thanks I'm going to give this a shot and hopefully it's agreeable to everyone! – B3Million Aug 17 '12 at 13:37
  • Thanks, Ive updated the solution with the solution in my comment – Jon Hazan Aug 17 '12 at 13:49
1

There is a 3rd EmailHeader option:

dlo.EmailHeader.triggerOtherEmail

This is meant to cover emails going outside the organisation but may be of help.

Also the salesforce example for this suggests passing the DMLOptions object in the update call: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_database_dmloptions.htm#emailheader

Database.DMLOptions dlo = new Database.DMLOptions();

dlo.EmailHeader.triggerAutoResponseEmail = true;

Case ca = new Case(subject='Plumbing Problems', contactid=c.id);

database.insert(ca, dlo);

Maybe you could try something like this: (Disclaimer: This code is untested)

    for(Case c : [Select Id,ownerId,status from Case where Id in :caseIds])
    {
        if(c.Status=='Initial')
        {
            c.ownerId = system.Userinfo.getUserId();
            casesList.add(c);
        }

    }

//THIS DMLOPTION SEEMS TO BE IGNORED IN BEFORE UPDATE TRIGGERS
Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerAutoResponseEmail = false;
dlo.EmailHeader.triggerUserEmail = false;
dlo.EmailHeader.triggerOtherEmail = false;

database.update(casesList,dlo);
2
  • Definitely, appreciated the feedback. But Using the triggerOtherEmail property (in addition to the other 2) had no effect the email still gets generated. I'm getting that sinking feeling that this is just default unmodifiable behavior. UGH. – B3Million Aug 15 '12 at 18:43
  • Sorry this didn't help you out! I've added another answer which I'm hoping will solve this. I'm more than sure its possible to disable the default email as we are using a custom email on our instance – Jon Hazan Aug 16 '12 at 8:49

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.