Loading

EmailHeader.triggerUserEmail doesn't prevent email notice from being sent

게시 일자: Jun 16, 2026
상세 설명


When an Apex trigger changes the owner of a Case or Lead record, Salesforce automatically sends an assignment notification email to the new owner. Setting DMLOptions.EmailHeader.triggerUserEmail = false does not suppress this notification email.

This behavior occurs because DMLOptions only applies to explicit DML operations made after the DML options are set. In a "before insert" or "before update" trigger context, there is no explicit DML call — the record update is implicit — so DMLOptions has no effect on the automatically generated assignment notification.

 

How to Reproduce the Issue

  1. Create a test user and set its email address to your own.
  2. Create a custom checkbox field called "Change Ownership" on the Case object.
  3. Create a before-insert/before-update trigger that uses DMLOptions with triggerUserEmail set to false, then reassigns the Case.OwnerId when the checkbox is checked.
  4. On an existing Case, check the "Change Ownership" checkbox. The assignment email notification is sent even though triggerUserEmail is set to false.

A similar issue occurs when changing Lead ownership.

trigger ChangeOwnership on Case (before insert, before update) { 
Database.DMLOptions dmo = new Database.DMLOptions(); 
dmo.EmailHeader.triggerUserEmail = false; 

for (Case c : Trigger.New){ 
if (c.Change_Ownership__c == true){ 
c.OwnerId='005i0000000QxRg'; // hard code the ID of the test user 
c.Change_Ownership__c = false; 
c.setOptions(dmo); 
} 
} 
}

 

솔루션

 

DMLOptions applies to DML calls made after the DML options are set. In a before-trigger context, the record update is implicit and not a separate DML call, so the DMLOptions setting has no effect on preventing the assignment notification email.

 

Workaround: Use an @future Asynchronous Method

The solution is to move the owner change logic to an @future method (an asynchronous Apex method that runs in a separate context). In the @future method, you perform an explicit DML update with DMLOptions applied, which correctly suppresses the assignment email notification.


The approach works as follows: the trigger collects the IDs of the Cases that require an ownership change and passes them to a @future method. Inside the @future method, you query for those Cases, update the OwnerId and reset the checkbox, then call Database.update with DMLOptions applied to perform the explicit DML. Because this is an explicit DML operation, DMLOptions correctly suppresses the email notification.

trigger ChangeOwnership_v2 on Case (before update) { 
List<ID> caseIDs = new List<ID>(); 

for (Case c : Trigger.New){ 
if (c.Change_Ownership__c == true){ 
caseIDs.add(c.Id); 
} 
} 

if(caseIDs.size() > 0) { 
CaseHelper.updateOwnership(caseIDs); 
} 
} 

public class CaseHelper { 

@future 
public static void updateOwnership(List<Id> caseIDs) { 
Database.DMLOptions dmo = new Database.DMLOptions(); 
dmo.EmailHeader.triggerUserEmail = false; 

List<Case> casesToUpdate = [select ownerid, change_ownership__c from case where id in :caseIDs]; 

for(Case c : casesToUpdate) { 
c.OwnerId='005i0000000QxRg'; 
c.Change_Ownership__c = false; 
} 

Database.update(casesToUpdate, dmo); // Actual DML operation is performed instead of implicit update
} 
}
Knowledge 기사 번호

000385933

 
로드 중
Salesforce Help | Article