The Salesforce.com user interface allows you to specify whether or not to send an email when the following events occur:
Creation of a new case or task
Creation of a case comment
Conversion of a case email to a contact
New user email notification
Password reset
In Apex scripts saved against API version 15.0 or later, the Database.DMLOptions emailHeader method enables you to specify additional information regarding the email that gets sent when one of the events occurs because of the script’s execution.
The following are the options that can be set with the emailHeader method:
- triggerAutoResponseEmail : Indicates whether to trigger auto-response rules (true) or not (false), for leads and cases. In the Salesforce.com user interface, 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.
- triggerOtherEmail : Indicates whether to trigger email outside the organization (true) or not (false). In the Salesforce.com user interface, this email can be automatically triggered by creating, editing,or deleting a contact for a case.
- triggerUserEmail : Indicates whether to trigger email that is sent to users in the organization (true) or not (false). In the Salesforce.com user interface, this email can be automatically triggered by a number of events; resetting a password, creating a new user, adding comments to a case, or creating or modifying a task.
In the following example, the triggerAutoResponseEmail option is specified:
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);
Recent Comments