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
KaityKaity 

Messaging.SingleEmailMessage and Messaging.MassEmailMessage

Can some one elaborately describe the : Messaging.SingleEmailMessage and Messaging.MassEmailMessage???? Where we use MassEmailMessage?

 

-Kaity

sambasamba

EmailTemplate emailTemplateInstance = [select Id from EmailTemplate where Name = 'RFI Notification: Search Criteria'];
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setTemplateId(emailTemplateInstance.Id);
email.setTargetObjectId(c.Owner.ContactId);
email.setWhatId(c.Id);
email.setSaveAsActivity(false);


Messaging.SendEmailResult [] r = Messaging.sendEmail(email);

 

Please see setWhatId and setTargetObjectId parmaeters.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound_mass.htm

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound_single.htm

subbu123.pbt@gmail.comsubbu123.pbt@gmail.com

Both are the usefull to send mail , Messaging.SingleEmailMessage for send single mail and  Messaging.MassEmailMessage for mass(more then one) mailss ,

 

 

This is example for  Messaging.SingleEmailMessage

List<Contact> conObj = [SELECT id, name FROM Contact LIMIT 100];

EmailTemplate e =  [select id,name from EmailTemplate limit 1];

for(Integer i=0; i < conObj.size(); i++){

Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
email.setTargetObjectId(conObj[i].Id);
email.setTemplateId(e.id);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });

}

 

 

 

 

souvik9086souvik9086

Both are good. You can find the details and the difference in my below post.

 

http://mindfiresfdcprofessionals.wordpress.com/2013/06/22/sending-mass-email-with-attachment/

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks