---
schema_version: "1"
id: 74fa58510e3019ef6ce4cd732ae3555021d4af5a84e380f7ad76a21edeefd700
title: MassEmailMessage Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_classes_email_outbound_mass.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_email_outbound_mass.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 0f855889f00a9816f42420713b48d9c134b9bd64b59a56c26bcc11b882030150
description: Contains methods for sending mass email.Creates a new instance of the Messaging.MassEmailMessage class.The description of the email. 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 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.
---
# MassEmailMessage Class

Contains methods for sending mass email.

## Namespace

[Messaging](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_Messaging.htm "The Messaging namespace provides classes and methods for Salesforce notifications and email functionality.")

## Usage

![Important](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/images/icon_note_important.png)

#### Important

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](https://help.salesforce.com/s/articleView?id=xcloud.security_email_verification_requirements.htm&language=en_US&type=5).

MassEmailMessage extends Email and inherits all of its methods. All base email (Email class) methods are also available to the MassEmailMessage objects.

- **[MassEmailMessage Constructors](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_email_outbound_mass.htm#apex_Messaging_MassEmailMessage_constructors)**
- **[MassEmailMessage Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_email_outbound_mass.htm#apex_Messaging_MassEmailMessage_methods)**

#### See Also

- [Email Class (Base Email Methods)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_email_outbound_base.htm#apex_classes_email_outbound_base "Contains base email methods common to both single and mass email.")

## MassEmailMessage Constructors

The following are constructors for MassEmailMessage.

- **[MassEmailMessage()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_email_outbound_mass.htm#apex_Messaging_MassEmailMessage_ctor)**  
    Creates a new instance of the Messaging.MassEmailMessage class.

### 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. All base email (Email class) methods are also available to the MassEmailMessage objects. These methods are described in [Email Class (Base Email Methods)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_email_outbound_base.htm#apex_classes_email_outbound_base "Contains base email methods common to both single and mass email.").

- **[setDescription(description)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_email_outbound_mass.htm#apex_Messaging_MassEmailMessage_setDescription)**  
    The description of the email.
- **[setTargetObjectIds(targetObjectIds)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_email_outbound_mass.htm#apex_Messaging_MassEmailMessage_setTargetObjectIds)**  
    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).
- **[setWhatIds(whatIds)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_email_outbound_mass.htm#apex_Messaging_MassEmailMessage_setWhatIds)**  
    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.

### setDescription(description)

The description of the email.

#### Signature

public Void setDescription(String description)

#### Parameters

- **description**:
    
    Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")

#### 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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_id.htm#apex_methods_system_id "Contains methods for the ID primitive data type.")\[\]

#### Return Value

Type: Void

#### Usage

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:

- 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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_id.htm#apex_methods_system_id "Contains methods for the ID primitive data type.")\[\]

#### Return Value

Type: Void

#### Usage

The values must be one of the following types:

- Contract
- Case
- Opportunity
- Product

![Note](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/images/icon_note.png)

#### Note

If you specify whatIds, specify one for each targetObjectId; otherwise, you will receive an INVALID\_ID\_FIELD error.