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
DanielJimenezDanielJimenez 

Email Triggers, Obey Database.Dmloptions.Emailheader?

Hi, I'm using Triggers to send out emails on "AfterUpdate", however I'd like the trigger to obey the DML options:

 

dml.EmailHeader.triggerUserEmail
dml.EmailHeader.triggerOtherEmail
dml.EmailHeader.triggerAutoResponseEmail

 

 

I figured it'd be as easy as an if statement making sure those variables are true, however I can't seem to find a way to read these variables, only set them. Is there any way to do this?

 

My first thought was to try the below, however it returned null:

 

 

Database.DMLOptions dml = new Database.DMLOptions();
System.debug(Logginglevel.info,dml.EmailHeader.triggerUserEmail);

Then for kicks, I tried:

 

System.debug(Logginglevel.info,Database.DMLOptions.EmailHeader);

 That didn't work either.

 

Any pointers? Is this possible?

 

Thanks in advance!,

Daniel

 

 

Pradeep_NavatarPradeep_Navatar

See the sample code below :

 

Database.DMLOptions dlo = new Database.DMLOptions();

dlo.EmailHeader.triggerUserEmail= true;

 

Did this answer your question? if so, please mark it solved.

DanielJimenezDanielJimenez
No it doesn't, please reread my question. Thanks!
fgwarb_1fgwarb_1
You need to set the DML options in the DML statment that is causing the trigger to execute, not the trigger execution itself.  6 years later, but hey when I found this thread so why not answer the question.
Grant Wickman 9Grant Wickman 9
I had a similar question and the answer isn't obvious so will share it here. If you want to know, from within a trigger what DML options have been set, then you actually need to query the DML options of the SObject itself.
The link below explains that SObjects have a getOptions() method. Query that to see what options have been set for the object.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm

To actually set options from within the trigger takes a bit of smoke and mirrors. That is explained here:
https://help.salesforce.com/apex/HTViewSolution?id=000176854&language=en_US

Hope this saves some ppl time in the future.