2

Can I use setToAddresses() with Messaging.MassEmailMessage?

I was going through the documentation for the MassEmailMessage class and in the setTargetObjectIds part it states

All emails must have a recipient value in at least one of the following fields: toAddresses ccAddresses bccAddresses targetObjectId

So I thought I should be able to set toAddresses somehow? Is there a way to do it without using a targetObjectId? I want to pass the email addresses as a List of strings.

Thank you!

3

Nope.

The MassEmailMessage class has the following methods:

  • setDescription(description)
    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).
  • 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.

In addition, it inherits the following methods from the Email class:

  • setBccSender(bcc)
    Indicates whether the email sender receives a copy of the email that is sent. For a mass mail, the sender is only copied on the first email sent.
  • setReplyTo(replyAddress)
    Optional. The email address that receives the message when a recipient replies.
  • setTemplateID(templateId)
    The ID of the template to be merged to create this email. You must specify a value for setTemplateId, setHtmlBody, or setPlainTextBody. Or, you can define both setHtmlBody and setPlainTextBody.
  • setSaveAsActivity(saveAsActivity)
    Optional. The default value is true, meaning the email is saved as an activity. This argument only applies if the recipient list is based on targetObjectId or targetObjectIds. If HTML email tracking is enabled for the organization, you will be able to track open rates.
  • setSenderDisplayName(displayName)
    Optional. The name that appears on the From line of the email. This cannot be set if the object associated with a setOrgWideEmailAddressId for a SingleEmailMessage has defined its DisplayName field.
  • setUseSignature(useSignature)
    Indicates whether the email includes an email signature if the user has one configured. The default is true, meaning if the user has a signature it is included in the email unless you specify false.
  • Thanks @AdrianLarson. So there is no way to set the recipients other than by setTargetObjectIds()? – Arthlete Mar 15 '16 at 21:07
  • @Arthlete Sure looks that way based on the documentation. I admit I have rarely used MassEmailMessage, but I would be surprised if an entire method went undocumented. – Adrian Larson Mar 15 '16 at 21:08
  • I need to set up a method that sends mass emails with different bodies. That's the only reason I chose MassEmailMessage. Can I pass different email bodies to SingleEmailMessage instead? @AdrianLarson – Arthlete Mar 15 '16 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.