MassEmailMessage Class

Contains methods for sending mass email.

Namespace

Messaging

Usage

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

MassEmailMessage Constructors

The following are constructors for MassEmailMessage.

MassEmailMessage()

Creates a new instance of the Messaging.MassEmailMessage class.

Signature

public MassEmailMessage()

MassEmailMessage Methods

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

setDescription(description)

The description of the email.

Signature

public Void setDescription(String description)

Parameters

description
Type: String

Return Value

Type: Void

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).

Signature

public Void setTargetObjectIds(ID[] targetObjectIds)

Parameters

targetObjectIds
Type: ID[]

Return Value

Type: Void

Usage

You can list up to 250 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.

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:
  • toAddresses
  • ccAddresses
  • bccAddresses
  • targetObjectId

setWhatIds(whatIds)

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.

Signature

public Void setWhatIds(ID[] whatIds)

Parameters

whatIds
Type: ID[]

Return Value

Type: Void

Usage

The values must be one of the following types:

  • Contract
  • Case
  • Opportunity
  • Product
Note

Note

If you specify whatIds, specify one for each targetObjectId; otherwise, you will receive an INVALID_ID_FIELD error.