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
rama krishna 181rama krishna 181 

5. is it possible to send email in triggers..?

5. is it possible to send email in triggers..?
vijayabhaskarareddyvijayabhaskarareddy
Hi@ Rama Krishna
Yes ! we can do the same using code below.

How we can send an Email from trigger along with existing email template.
Knowledge Article Number000188017
Description   
Send email from Apex code using Email Template already created in the org. Also, to fetch email address from target objects (Lead, Contact).
 
 
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 

List <Contact> Con= [select id, name from Contact where name =:'Mithilesh Kumar']; 

mail.setTargetObjectId(Con[0].id); 

mail.setSenderDisplayName('Salesforce Support'); 

mail.setUseSignature(false); 

mail.setBccSender(false); 

mail.setSaveAsActivity(false); 

EmailTemplate et=[Select id from EmailTemplate where Name=:'SFDC TEST']; 

mail.setTemplateId(et.id); 


Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 I Hope ,it will help you