+ Start a Discussion
MC2014MC2014 

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)
Hi,

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.

Thanks,
N.J
MC2014MC2014
@N.J,
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.
MC2014MC2014
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;
			c.setOptions(dlo);

			updateCaseList.add(c);
		}
		
		if(updateCaseList.size() > 0){
			database.update(updateCaseList);
		}

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