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.
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.
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
}
}000385933

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.