Even though auto-sent emails can be triggered by actions in the Salesforce user interface, the DMLOptions settings for emailHeader take effect only for DML operations carried out in Apex code.
Account a = new Account(name='Acme Plumbing'); insert a; Contact c = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber', accountid=a.id); insert c; Database.DMLOptions dlo = new Database.DMLOptions(); dlo.EmailHeader.triggerAutoResponseEmail = true; Case ca = new Case(subject='Plumbing Problems', contactid=c.id); database.insert(ca, dlo);
Suppose that you use an after-insert or after-update trigger to change ownership of leads, contacts, or opportunities. If you use the API to change record ownership, or if a Lightning Experience user changes a record’s owner, no email notification is sent. To send email notifications to a record’s new owner, set the triggerUserEmail property to true.
The following are properties for DmlOptions.EmailHeader.
public Boolean triggerAutoResponseEmail {get; set;}
Type: Boolean
This email can be automatically triggered by a number of events, for example creating a case or resetting a user password. If this value is set to true, when a case is created, if there is an email address for the contact specified in ContactID, the email is sent to that address. If not, the email is sent to the address specified in SuppliedEmail
public Boolean triggerOtherEmail {get; set;}
Type: Boolean
This email can be automatically triggered by creating, editing, or deleting a contact for a case.
public Boolean triggerUserEmail {get; set;}
Type: Boolean
This email can be automatically triggered by a number of events; resetting a password, creating a new user, or creating or modifying a task.