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
sureshcsksureshcsk 

SingleEmailMessage working like MassEmailMessage !!!!!!!!!!!

Hi.

 

1.In Contact object created a custome field called Group.

 

Group values like A,B,C..

 

2.I queried the email id from the Contact object according to user Group reguest.

Let us consider we took all email ids related to Group A.

 

public List<String> email_list;

public List<Contact> emailaddress;

 

 

emailaddress = new List<Contact>();

 


/******* get all email address related to Group *******/

 

emailaddress = [Select email From Contact Where Contact.group__c =:groupvalue];

no_ofemail = integer.valueOf(emailadd.size());
email_list = new String[no_ofemail];

 

 

 /******* added all the retrieved  email address to a String list email_list*******/

 

 for( Contact tempemail : emailaddress)
        {
        email_list[i] =tempemail.email;
        i++;
        }  

 

3.Sending email to Group A members

 

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setbccAddresses(email_list);
mail.setSubject(template_subject);
mail.setPlainTextBody(template_body);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 

 

I used only SingleEmailMessage() but email is sent to all

the email address which exists in the email_list <List>.

 

Then whats the difference between  SingleEmailMessage and MassEmailMessage.

 

 

 

 

 

 

 

Cool_DevloperCool_Devloper

Suresh,

The Single Email message can send message related to only single record whereas mass email message can send mails related to multiple records (WhatId and TargetObjectId).

Within a single email message, you can surely have a list of reciepients!! you can refer to the apex documentation for further details and use cases.

Cool_D

sureshcsksureshcsk

Hi Cool_D

 

Thank you very much for your prompt reply.

Once again I chekced the Apex Doc.

 

I found that when using the "Single Email Message" the method

setToAddresses() allowed maximum number of email addresses is ten.

 

When I passed List<mylist> as the parameter to setToAddresses(),

<mylist>  had only 4 email addresses ,so I think Single Email Message worked

fine without any problem.

 

cheers

suresh

 

 

 

 

Cool_DevloperCool_Devloper

Yes Suresh, i agree with that. That is what i wrote in my post above!!

You can send single email message to multiple reciepients as you mentioned, but only on a single record. Whereas, MassEmailMessage can send emails to multiple objects/targets as well.

Cool_D