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
Pranav ChitransPranav Chitrans 

wrtie trigger with helper c;ass to send email when new conatc is inserted when email filled

I have Write a trigger on Contact , when a contact insert an email should be sent to contact email id with specified template. I have written the code & it doesm't give any error but i am not getting my result... i want to wrtie with helper class... it woked fine for me with direct trigger...
****APEX TRIGGER*****
trigger helperSendEmailTOCon on Contact (after Insert, after Update) 
{
 helperClassSendEmailToCon obj = new helperClassSendEmailToCon();
 if(trigger.isInsert && trigger.isAfter)
 {
  obj.onAfterInsert(trigger.new);
 }
}
****APEX CLASS****
public class helperClassSendEmailToCon
{
 
 public void onAfterInsert(List<Contact> triggerNew)
 {
  InsertEmailOnContact(triggerNew);
 }
 
 void InsertEmailOnContact(List<Contact> triggerNew)
 {  
  EmailTemplate et = [select id from EmailTemplate where name =:'InsertContact'];
  List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();  
  for(Contact con : triggerNew)
  {
   if(con.email!=null)
   {
    Messaging.singleEmailMessage singleEmail = new Messaging.singleEmailMessage();
    List<String> sendTo = new List<String>();
    singleEMail.setCcAddresses(sendTo);
    singleEMail.setTargetObjectId(con.Id); 
    singleEmail.setTemplateId(et.Id);
    singleEmail.setSaveAsActivity(false);
    emails.add(singleEmail );
   }
  }
  messaging.sendEmail(emails); 
 } 
}

PLZ HELP ME WITH THIS CODE
 
Best Answer chosen by Pranav Chitrans
Pranav ChitransPranav Chitrans
I found the soultion... thanx to Abhishek bansal :)
in apex class at line 11 just i have to remove :
EmailTemplate et = [select id from EmailTemplate where name = 'InsertContact'];