Find your content:

Search form

You are here

Case Assignment Notification Suppression

 
Share

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??


Attribution to: B3Million

Possible Suggestion/Solution #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);

Attribution to: Jon Hazan

Possible Suggestion/Solution #2

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


Attribution to: Jon Hazan
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/446

My Block Status

My Block Content