function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NikhilNikhil 

How to use for Messaging.MassEmailMessage

Hi Forum members,

I am trying to send emails via Messaging.MassEmailMessage in Apex trigger.

I am not able to save the trigger

Code i used for that is
/////////////////////////////////////
trigger mytrigger on Account (after update)
{
    if (Trigger.isAfter && Trigger.isUpdate)
    {

           String[] toAddresses = new String[]{'xyz@abc.com', 'ijk@abc.com'};
           Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
            mail = new Messaging.MassEmailMessage();
            mail.setToAddresses(toAddresses);
            mail.setPlainTextBody(' test mails ');
            mail.setSenderDisplayName('ABCD corp') ;
            Messaging.sendEmail(new Messaging.MassEmailMessage[] {mail});

    }
}
/////////////////////////////////////

now i am not able to save this cause,i think i am missing something in this cause mail object of Messaging.MassEmailMessage  is not recognizing "setToAddresses"  method and other methods

Please advice the right way to use this for massmailing
My requirement is to post emailbody to various contacts

Thanks
Nikhil


Message Edited by Nikhil on 10-22-2008 12:36 AM
eyewelleyewell
according to the Docs, the setToAddresses is a function of the Single Email Object.
For mass email, try passing in a list of contact object IDs...

Also, FYI in your code above, you are instantiating the mass email object twice, both when you declare it, and then the line below that.... You can delete that second one.



Message Edited by eyewell on 10-22-2008 01:35 PM
Sami CohenSami Cohen

Hi Nikhil,

I'm trying to use the mass email like you and I encoutered the same problem you mentioned.
Did you succeed?

Thanks,

 



Message Edited by Sami Cohen on 12-12-2008 01:32 AM