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
l.trincil.trinci 

Mass email with email template

I know that the email template on mass email is related only to user and contact, but my question is: there is a way to do a mass email on a custom object?!

 

This is my apex class:

 


public with sharing class MassEmail
{
public List<Applicant_test__c> usr{get;set;} //
public List<String> usr_email{get;set;}
public Map<string,string> Map_usr{get;set;}
public string emailid{get;set;}
public string provaemail;
Contact con = new contact();


public void getprovaemail()
{
Contact con = new contact();
con = [Select Id from Contact where Id = :'a0D?fcf=00Bd0000003kLEZ'];
usr=new List<Applicant_test__c>();
usr_email=new List<String>();
usr.clear();
usr_email.clear();
usr=[select Email__c from Applicant_test__c where Keep_in_touch__c=true];
for(Applicant_test__c u : usr)
{
system.debug('___________Email______________'+u.Email__c);
if(u.Email__c!=null)
usr_email.add(u.Email__c);
}
if(usr_email.size()>0)
sendmail(usr_email);
}
public void sendmail(List<String> str)
{
Messaging.reserveSingleEmailCapacity(4);
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

EmailTemplate EmailTemp = [SELECT id FROM EmailTemplate WHERE developerName = 'Standard_New_Interview'];
email.setTemplateId(EmailTemp.Id);
email.setSaveAsActivity(true);

 


//email.setTargetObjectId(Applican_test id);



Messaging.sendEmail(New Messaging.SingleEmailMessage[]{email});

}
}

 

 

Thanks in advance

Best Answer chosen by Admin (Salesforce Developers) 
Niket SFNiket SF

Hello trinci,

 

 

          In the mass email I am not sure you can user Visual force email template but there is no way to to mass email on custom object. You need to dynamically create the HTML body and merge the fields in the email and by using the email field you need to send the email

 

Thanks 

Nik's

 

 

Skype name : niket.chandane