SingleEmailMessage Methods

Contains methods for sending single email messages.

Namespace

Messaging

Usage

All base email (Email class) methods are also available to the SingleEmailMessage objects.

SingleEmailMessage Constructors

The following are constructors for SingleEmailMessage.

SingleEmailMessage()

Creates a new instance of the Messaging.SingleEmailMessage class.

Signature

public SingleEmailMessage()

SingleEmailMessage Methods

The following are methods for SingleEmailMessage. All are instance methods.

setBccAddresses(String[])

Optional. A list of blind carbon copy (BCC) addresses. The maximum allowed is 25. This argument is allowed only when a template is not used.

Signature

public Void setBccAddresses(String[] bccAddresses)

Parameters

bccAddresses
Type: String[]

Return Value

Type: Void

Usage

At least one value must be specified in one of the following fields: toAddresses, ccAddresses, bccAddresses, targetObjectId, or targetObjectIds.

If the BCC compliance option is set at the organization ​level, the user cannot add BCC addresses on standard messages. The following error code is returned: BCC_NOT_ALLOWED_IF_BCC_ COMPLIANCE_​ENABLED. ​Contact your salesforce.com representative for information on BCC compliance.

setCcAddresses(String[])

Optional. A list of carbon copy (CC) addresses. The maximum allowed is 25. This argument is allowed only when a template is not used.

Signature

public Void setCcAddresses(String[] ccAddresses)

Parameters

ccAddresses
Type: String[]

Return Value

Type: Void

Usage

All email must have a recipient value of at least one of the following:
  • toAddresses
  • ccAddresses
  • bccAddresses
  • targetObjectId
  • targetObjectIds

setCharset(String)

Optional. The character set for the email. If this value is null, the user's default value is used.

Signature

public Void setCharset(String charset)

Parameters

charset
Type: String

Return Value

Type: Void

setDocumentAttachments(ID[])

Optional. A list containing the ID of each document object you want to attach to the email.

Signature

public Void setDocumentAttachments(ID[] docAttachments)

Parameters

docAttachments
Type: ID[]

Return Value

Type: Void

Usage

You can attach multiple documents as long as the total size of all attachments does not exceed 10 MB.

setFileAttachments(EmailFileAttachment[])

Optional. A list containing the file names of the binary and text files you want to attach to the email.

Signature

public Void setFileAttachments(EmailFileAttachment[] fileAttachments)

Parameters

fileAttachments
Type: Messaging.EmailFileAttachment[]

Return Value

Type: Void

Usage

You can attach multiple files as long as the total size of all attachments does not exceed 10 MB.

setHtmlBody(String)

Optional. The HTML version of the email, specified by the sender. The value is encoded according to the specification associated with the organization. You must specify a value for setTemplateId, setHtmlBody, or setPlainTextBody. Or, you can define both setHtmlBody and setPlainTextBody.

Signature

public Void setHtmlBody(String htmlBody)

Parameters

htmlBody
Type: String

Return Value

Type: Void

setInReplyTo(String)

Optional. The In-Reply-To field of the outgoing email. Identifies the email or emails to which this one is a reply (parent emails). Contains the parent email or emails' message-IDs.

Signature

public Void setInReplyTo(String inReplyTo)

Parameters

inReplyTo
Type: String

Return Value

Type: Void

setPlainTextBody(String)

Optional. The text version of the email, specified by the sender. You must specify a value for setTemplateId, setHtmlBody, or setPlainTextBody. Or, you can define both setHtmlBody and setPlainTextBody.

Signature

public Void setPlainTextBody(String plainTextBody)

Parameters

plainTextBody
Type: String

Return Value

Type: Void

setOrgWideEmailAddressId(ID)

Optional. The ID of the organization-wide email address associated with the outgoing email. The object's DisplayName field cannot be set if the setSenderDisplayName field is already set.

Signature

public Void setOrgWideEmailAddressId(ID emailAddressId)

Parameters

emailAddressId
Type: ID

Return Value

Type: Void

setReferences(String)

Optional. The References field of the outgoing email. Identifies an email thread. Contains the parent emails' References and message IDs, and possibly the In-Reply-To fields.

Signature

public Void setReferences(String references)

Parameters

references
Type: String

Return Value

Type: Void

setSubject(String)

Optional. The email subject line. If you are using an email template, the subject line of the template overrides this value.

Signature

public Void setSubject(String subject)

Parameters

subject
Type: String

Return Value

Type: Void

setTargetObjectId(ID)

Required if using a template, optional otherwise. The ID of the contact, lead, or user to which the email will be sent. The ID you specify sets the context and ensures that merge fields in the template contain the correct data.

Signature

public Void setTargetObjectId(ID targetObjectId)

Parameters

targetObjectId
Type: ID

Return Value

Type: Void

Usage

Do not specify the IDs of records that have the Email Opt Out option selected.

All email must have a recipient value of at least one of the following:
  • toAddresses
  • ccAddresses
  • bccAddresses
  • targetObjectId
  • targetObjectIds

setToAddresses(String[])

Optional. A list of email addresses to which you are sending the email. The maximum number of email addresses allowed is 100. This argument is allowed only when a template is not used.

Signature

public Void setToAddresses(String[] toAddresses)

Parameters

toAddresses
Type: String[]

Return Value

Type: Void

Usage

All email must have a recipient value of at least one of the following:
  • toAddresses
  • ccAddresses
  • bccAddresses
  • targetObjectId
  • targetObjectIds

setWhatId(ID)

Optional. If you specify a contact for the targetObjectId field, you can specify a whatId as well. This helps to further ensure that merge fields in the template contain the correct data.

Signature

public Void setWhatId(ID whatId)

Parameters

whatId
Type: ID

Return Value

Type: Void

Usage

The value must be one of the following types:

  • Account
  • Asset
  • Campaign
  • Case
  • Contract
  • Opportunity
  • Order
  • Product
  • Solution
  • Custom
© Copyright 2000–2014 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.