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
NareshKrishnaNareshKrishna 

Email Template Id

Hi,

 

I have created a template under "Personal Email Template" for sending email.

 

 

Im using the below code to send an email but showing an error

"SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Missing target address (target, to, cc, bcc): []  "

 

Controller :



private final Contact con;   

public testemail(ApexPages.StandardController controller){

        this.con=(Contact)controller.getRecord();    }       

public void SendEmail(){           

 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();                      

 

//Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();       

//mail.setTargetObjectId(con.Id);       

//mail.setTemplateId('00X90000000QHUD');           

mail.setWhatId(con.Id);              

mail.setBccSender(false);           

mail.setUseSignature(false);           

mail.setReplyTo('abc@gmail.com');           

mail.setSenderDisplayName('user123');           

mail.setSaveAsActivity(false); 

 

can any one please help me on how to fetch the email template id to set in "mail.setTemplateId( );". 

 

Thanks

 

 

 


 

 

 

Sam27Sam27

EmailTemplate et = [select id from EmailTemplate where developername='your_template_name'];  // replace your_template_name from the api name of your template you can get that from template page

 

mail.setTemplateId(et.id);

you should uncomment the setTargetObjectId  and the error which you are gtting seems that setTargetObjectId is not getting the Contact Id you are putting. 

 

Hope that helps

 

Sam