MassEmailMessage Class
Contains methods for sending mass email.
Sending an email by using Apex requires domain-level and user-level email verification. System-generated emails also require verification of the From email address. Email delivery fails if any of these verifications is incomplete. See Requirements to Send Email from Salesforce.
MassEmailMessage extends Email and inherits all of its methods. All base email (Email class) methods are also available to the MassEmailMessage objects.
See Also
The following are constructors for MassEmailMessage.
-
Creates a new instance of the
Messaging.MassEmailMessageclass.
Creates a new instance of the Messaging.MassEmailMessage class.
public MassEmailMessage()
The following are methods for MassEmailMessage. All are instance methods. All base email (Email class) methods are also available to the MassEmailMessage objects. These methods are described in Email Class (Base Email Methods).
-
The description of the email.
-
setTargetObjectIds(targetObjectIds)
A list of IDs of the contacts, leads, or users to which the email will be sent. The IDs you specify set the context and ensure that merge fields in the template contain the correct data. The objects must be of the same type (all contacts, all leads, or all users).
-
Optional. If you specify a list of contacts for the
targetObjectIdsfield, you can specify a list ofwhatIdsas well. This helps to further ensure that merge fields in the template contain the correct data.
The description of the email.
public Void setDescription(String description)
-
description:
Type: String
Type: Void
A list of IDs of the contacts, leads, or users to which the email will be sent. The IDs you specify set the context and ensure that merge fields in the template contain the correct data. The objects must be of the same type (all contacts, all leads, or all users).
public Void setTargetObjectIds(ID[] targetObjectIds)
-
targetObjectIds:
Type: ID[]
Type: Void
You can list multiple IDs per email. If you specify a value for the targetObjectIds field, optionally specify a whatId as well to set the email context to a user, contact, or lead. This ensures that merge fields in the template contain the correct data. Each ID counts against the sending organization’s daily mass email limit, except for user IDs. Each ID counts against the sending organization’s daily mass email limit, except for IDs of users in the organization.
Do not specify the IDs of records that have the Email Opt Out option selected.
All emails must have a recipient value in at least one of the following fields:
toAddressesccAddressesbccAddressestargetObjectId
Optional. If you specify a list of contacts for the targetObjectIds field, you can specify a list of whatIds as well. This helps to further ensure that merge fields in the template contain the correct data.
public Void setWhatIds(ID[] whatIds)
-
whatIds:
Type: ID[]
Type: Void
The values must be one of the following types:
- Contract
- Case
- Opportunity
- Product
If you specify whatIds, specify one for each targetObjectId; otherwise, you will receive an INVALID_ID_FIELD error.