function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
isdevisdev 

Allow disable of "send notification email" when updating lead owner via APEX

Hello,

I have a trigger that is changing the owner (After update, After insert)  and each time the owner is change a  notification email is sent to the new owner.

It seems it cannot be disable even with the DML option :

Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerAutoResponseEmail = false;
dlo.EmailHeader.triggerOtherEmail = false;
dlo.EmailHeader.triggerUserEmail = false;
dlo.assignmentRuleHeader.useDefaultRule= false;
database.update(LeadstoUpdate,dlo);

Is there another way to disable this email  ? I found a lot of post asking that but no real solution.

Thanks for your help
Ashish_SFDCAshish_SFDC

Hi , 


To avoid such kind of sitiation we use a boolean variable in an If loop. 

If (Booleen = 0 ) {

Process 
}

Else 

Dont Process 

Try if you can implement the same logic in your Code. 


Regards,

Ashish
 

isdevisdev
Thanks for the answer, but  i want to disable a default salesforce.com email notification i'm not sending.
Abhi_TripathiAbhi_Tripathi
Hi,

Using apex, this is the only way to enable or disable Send Email Notificaiton

This is how its done

//List of task
List<Task> taskClone = [Select Id From Task Where Id=:tasks.keySet()];
   
//Set EmailHeader.triggerUserEmail to fasle, this disables send Email notification 
Database.DMLOptions dmlo = new Database.DMLOptions();
dmlo.EmailHeader.triggerUserEmail = false;

//Update
database.update(taskClone, dmlo);

Hope this helps

Regards,
Abhi Tripathi
Salesforce Developer

isdevisdev
Ok this is my conclusion too but it's not working for lead assignement notification so that's why i'm asking.