You need to sign in to do that
Don't have an account?

Change owner in trigger - remove automatic email
Hello,
We have added a field "Assign to" on Case (a lookup on user) to let Salesforce.com users the ability to change the owner of a case from the case list. The Case owner is then updated via a trigger (before update on case) that is copying the "Assign to" field value into the Case.owner field.
The trigger works fine and the case owner is updated correctly.
The issue is that when the case owner is updated via that procedure, an automatic email is sent to the new Case owner to warn him that he s now assigned to the case. We do NOT want this email to be sent.
How can we prevent that email to be sent? Is there a piece of code available for that?
Here is the code I'm using currently:
trigger AssignToCaseOwner on Case (before update) { Integer i = 0; for(Case theCase : System.Trigger.new) { // only executed if the case owner is not changed as well // and if the case owner is not already the "Assign to" user if(theCase.OwnerId == System.Trigger.old.get(i).OwnerId && theCase.Assign_to__c != null && theCase.Assign_to__c != System.Trigger.old.get(i).Assign_to__c && theCase.OwnerId != theCase.Assign_to__c) { theCase.OwnerId = theCase.Assign_to__c; // set DML options to remove the auto email -> NOT WORKING Database.DMLOptions dlo = new Database.DMLOptions(); dlo.EmailHeader.triggerUserEmail = false; theCase.setOptions(dlo); } // Make the "Assign to" field empty as we do not need the value // to be stored in the record theCase.Assign_to__c = null; i++; } }
Thanks on beforehand,
Martin HUBERT.
create a checkbox field in the backend defalut as false and dont expose that field in the lay out...and in the updation make that field as true and change the workflow logic as when the new field value is false and your previous condition.. then in the second scenario it will never send an email.. hope you got my point...
I understand u dont want to send a mail to the new case owner when a case is assigned to him. For this u have to modify the support settings in case object.
Thanks,
Malar
try with this once
If it does not work please let me know this statement "case owner is updated via that procedure," what do you mean by procedure ant apex class method?
No need to write to code for it. It's configuration change.
Go to setup->customize-> case ->support settings -> Notify Case Owners when Case Ownership Changes; and uncheck that checkbox.
Unfortunately, this solution doesn't work... it is already unchecked...
Any other alternatives?
This is not working. The email is still sent out (I've removed the line that is not compiling before testing).
By procedure, I meant the piece of code in the trigger does update the case owner (meaning the piece of code works fine) but an email I'm not expecting is sent automatically.
A colleague told me it is a bug in SFDC... does someone knows more about it?
Thanks anyway.
I've been working on this for hours, same issue. I've ruled out pretty much every documented control that has anything to do with email notification, and I do not think this is something that can be controlled through Setup menus or through Apex.
To recap: the problem is that in all other instances where case ownership is changed, the email notification to the new case owner is not sent. But when the trigger runs that reassigns a case to a new owner, the email notification is sent. I don't want this to happen.
Here's the code I've written for the trigger. You can see I've tried the Database.DMLOptions methods to prevent the auto email. Based on the fact that these methods fail, I think they do not have any bearing on case email notifications, (which is probably why emails notifications on case updates are not listed in the documented events that DMLOptions are meant to impact).
This thread is several months old and if anyone has found a solution to it I'd love to hear about it.
This is interesting, we are having a similar issue with apex changing the owner of a Lead. We haven't tried hanging the DML settings to prevent the email notification, when we do we will bear in mind that it might NOT work and then report a case to salesforce.
Has there been any resolution to this issue? I'm encountering the exact same thing in my own Case trigger. I'm programmaticly changing the Case Owner to a Queue in my trigger and when this happens it emails every user assigned to the queue. I've written my own custom email alerts so I really don't want to spam everyone whenever this trigger fires. I've already disabled the Automatic Case Notification option under Setup > Customize > Case > Support Settings and the email is still being sent. Any suggestions?
Thanks in advance.
Has anyone figured out a solution to this one? Running into the same problem and hoping there is a work-around.
I was able to get things working in my org by doing a combination of things. First of all, as suggested previously in this thread, you need to disable automatic email alerts via the Setup menu (Case > Support Settings > Notify Case Owners when Case Ownership Changes) which will disable emails when the owner changes from one User to another.
My situation was complicated because I was often changing the Case Owner to one of the Queue's I had created. In order to prevent these emails from firing, I had to adjust the Queue settings under the Setup menu. These settings can be found under Administration Setup > Manage Users > Queues and selecting the Queue of interest. To disable all emails, I had to set the Queue email to a non-existant address and uncheck the Send Email to Queue Members checkbox.
These two solutions allowed me to suppress all Salesforce generated Case notifications with one exception: when a User manually changed the owner to another user using the "Change" link next to the Case Owner field and manually checked the Send Notification Email checkbox.
Hi, Thanks for the quick reply. Unfortunately, we have all of the config turned off like you do, but it's still sending the email when the trigger makes the adjustment. When a user does it normally, we're all set, but the trigger seems to be ignoring the config settings. Harry
https://help.salesforce.com/apex/HTViewSolution?id=000176854&language=en_US
HTH