+ Start a Discussion

Change case owner in Apex causes email notification to be sent out.

I made sure that under develop -> case -> custom settings > Notify Case Owners when Case Ownership Changes is unchecked.

When I change owner through a before update trigger it ends up sending out an email to the new owner. Any thoughts?

trigger CaseTrigger on Case (before update) {
	for(Case c : trigger.new) {
		c.owner = xxx;


Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)

Check if Notify Default Owner field is checked on Case>> Support Setting.

Also you can use DML options to restrict firing UserEmails in your apex code.
You might want to visist https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_class_Database_EmailHeader.htm for more information on DML options.

The field is checked, but the default user isn't the one that has been changed to.

Also, since I am not using any DML statemetns, how would I restrict it before the update.
So I changed the trigger to after trigger, and include the DML email header still getting those emails.
                for (Case c : caseList){
			c.OwnerId = 'xx'
			Database.DMLOptions dlo = new Database.DMLOptions();
			dlo.EmailHeader.triggerAutoResponseEmail = false;
			dlo.EmailHeader.triggerOtherEmail = false;
			dlo.EmailHeader.triggerUserEmail = false;

		if(updateCaseList.size() > 0){

I just found out that "Case Assigned Template" has been set, but "Notify Case Owners when Case Ownership Changes" is still uncheck.

Shouldn't the DML emailheader I've set, supercede?