The following are methods for Messaging. All are instance methods.
public static Messaging.InboundEmail extractInboundEmail(Object source, Boolean includeForwardedAttachments)
Type: Messaging.InboundEmail
public Void reserveMassEmailCapacity(Integer amountReserved)
Type: Void
This method can be called when you know in advance how many addresses emails will be sent to as a result of the transaction.If the transaction would cause the organization to exceed its daily email limit, using this method results in the following error: System.HandledException: The daily limit for the org would be exceeded by this request.If the organization doesn’t have permission to send API or mass email, using this method results in the following error: System.NoAccessException: The organization is not permitted to send email.
public Void reserveSingleEmailCapacity(Integer amountReserved)
Type: Void
This method can be called when you know in advance how many addresses emails will be sent to as a result of the transaction.If the transaction would cause the organization to exceed its daily email limit, using this method results in the following error: System.HandledException: The daily limit for the org would be exceeded by this request.If the organization doesn’t have permission to send API or mass email, using this method results in the following error: System.NoAccessException: The organization is not permitted to send email.
public Messaging.SendEmailResult[] sendEmail(Messaging.Email[] emails, Boolean allOrNothing)
The optional opt_allOrNone parameter specifies whether sendEmail prevents delivery of all other messages when any of the messages fail due to an error (true), or whether it allows delivery of the messages that don't have errors (false). The default is true.
Type: Messaging.SendEmailResult[]
public Messaging.SendEmailResult[] sendEmailMessage(List<ID> emailMessageIds, Boolean allOrNothing)
Type: Messaging.SendEmailResult[]
The sendEmailMessage method assumes that the optional opt_allOrNone parameter is always false and ignores the value you set. This optional parameter specifies whether sendEmailMessage prevents delivery of all other messages when any of the messages fail due to an error (true), or whether it allows delivery of the messages that don't have errors (false).
This example shows how to send a draft email message. It creates a case and a new email message associated with the case. Next, the example sends a draft email message and checks the results. Before running this example, make sure to replace the email address with a valid address.
Case c = new Case(); insert c; EmailMessage e = new EmailMessage(); e.parentid = c.id; // Set to draft status. // This status is required // for sendEmailMessage(). e.Status = '5'; e.TextBody = 'Sample email message.'; e.Subject = 'Apex sample'; e.ToAddress = 'customer@email.com'; insert e; List<Messaging.SendEmailResult> results = Messaging.sendEmailMessage(new ID[] { e.id }); System.assertEquals(1, results.size()); System.assertEquals(true, results[0].success);
public static List<Messaging.RenderEmailTemplateBodyResult> renderEmailTemplate(String whoId, String whatId, List<String> bodies)
Type: List<Messaging.RenderEmailTemplateBodyResult>
Use this method in situations in which you want to dynamically compose blocks of text that are enriched with data from the database. You can then use the the rendered blocks of text to compose and send an email or update a text value in another database record.
Executing the renderEmailTemplate method counts toward the SOQL governor limit. The number of SOQL queries that this method consumes is the number of elements in the list of strings passed in the bodies parameter.
public static Messaging.SingleEmailMessage renderStoredEmailTemplate(String templateId, String whoId, String whatId)
Executing the renderStoredEmailTemplate method counts toward the SOQL governor limit as one query.
public static Messaging.SingleEmailMessage renderStoredEmailTemplate(String templateId, String whoId, String whatId, Messaging.AttachmentRetrievalOption attachmentRetrievalOption)
When the attachmentRetrievalOption parameter is not set to NONE, the entityAttachments property of Messaging.SingleEmailMessage contains the ID of the Salesforce content objects to attach (ContentVersion or Document). The fileAttachments property contains the IDs of attachments, in addition to all the IDs in the entityAttachments property. As a result, the ID values in entityAttachments are duplicates of the IDs in the fileAttachments property. If you call renderStoredEmailTemplate() by passing the METADATA_WITH_BODY option, and send the rendered email message, the email will contain duplicate attachments. Before using the returned email message with sendEmail(emails, allOrNothing), you can remove attachments from fileAttachments that are duplicated in entityAttachments.
Executing the renderStoredEmailTemplate method counts toward the SOQL governor limit as one query.
public static Messaging.SingleEmailMessage renderStoredEmailTemplate(String templateId, String whoId, String whatId, Messaging.AttachmentRetrievalOption attachmentRetrievalOption, Boolean updateEmailTemplateUsage)
When the attachmentRetrievalOption parameter is not set to NONE, the entityAttachments property of Messaging.SingleEmailMessage contains the ID of the Salesforce content objects to attach (ContentVersion or Document). The fileAttachments property contains the IDs of attachments, in addition to all the IDs in the entityAttachments property. As a result, the ID values in entityAttachments are duplicates of the IDs in the fileAttachments property. If you call renderStoredEmailTemplate() by passing the METADATA_WITH_BODY option, and send the rendered email message, the email will contain duplicate attachments. Before using the returned email message with sendEmail(emails, allOrNothing), you can remove attachments from fileAttachments that are duplicated in entityAttachments.
Executing the renderStoredEmailTemplate method counts toward the SOQL governor limit as one query.