+ Start a Discussion
Cheerag VijayaCheerag Vijaya 

Send e-mail

Hi! When I click a button on the VF page, I need to send e-mail to 4 members and the e-mail body should be same for all the 4 members. What can I do ?
Harish RamachandruniHarish Ramachandruni
public PageReference send(List<Account> accountIds)
        Map<Id, Contact> contactMap = new Map<Id, Contact>([SELECT Id, Email FROM Contact WHERE AccountId IN :accountIds]);

        EmailTemplate template =  [SELECT Id, Name FROM EmailTemplate WHERE DeveloperName = 'My_Unique_API_Name' LIMIT 1];

        Messaging.MassEmailMessage emails=new Messaging.MassEmailMessage(); 
        Messaging.SendEmail(New Messaging.MassEmailMessage[]{emails});

        return null;

Lance Shi 8Lance Shi 8
Harish's code pretty much demonstrate what you need to do here. To send emails to multiple contacts, simple put their contact Id as a String list and use that as a parameter passed into emails.setTargetObjectIds(). Then you will be able to send the emails.