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

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:





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();

Then for kicks, I tried:



 That didn't work either.


Any pointers? Is this possible?


Thanks in advance!,





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.

No it doesn't, please reread my question. Thanks!
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.

To actually set options from within the trigger takes a bit of smoke and mirrors. That is explained here:

Hope this saves some ppl time in the future.