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
shalushalu 

if new contact is created send welcome email to that contact.if contact is updated send email to that contact like contacts is updated successfully like that in triggers

Best Answer chosen by shalu
sfdcMonkey.comsfdcMonkey.com
else use following apex trigger and class code :

apex class :
public class emailSendClass {
    public static void emailSendToContact(List<contact> triggernew, string sSubject, string sBody){
         // Step 0: Create a master list to hold the emails we'll send
  List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
  
  for (Contact myContact : triggernew) {
    if (myContact.Email != null) {
      Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    
      // Step 2: Set list of people who should get the email
      List<String> sendTo = new List<String>();
      sendTo.add(myContact.Email);
      mail.setToAddresses(sendTo);
    
      // Step 3: Set who the email is sent from
      mail.setReplyTo('sirdavid@bankofnigeria.com');  //update it with your desired email 
      mail.setSenderDisplayName('Official Bank of Nigeria'); //update it with your desired Name 
     
      // (Optional) Set list of people who should be CC'ed
      List<String> ccTo = new List<String>();
      ccTo.add('test@gmail.com');
      mail.setCcAddresses(ccTo);

      // Step 4. Set email contents - you can use variables!
      mail.setSubject(sSubject);
      String body = 'Dear ' + myContact.LastName + ', ';
      body += sBody;
    
      mail.setHtmlBody(body);
    
      // Step 5. Add your email to the master list
      mails.add(mail);
    }
  }
  // Step 6: Send all emails in the master list
  Messaging.sendEmail(mails);
    }
}

trigger :
trigger sendEmail on Contact (after insert, after update) {
    if(trigger.isInsert && trigger.isAfter){
        emailSendClass.emailSendToContact(trigger.new, 'New Contact Created', 'You contact created successfully');
    }
    else if(trigger.isUpdate && trigger.isAfter){
        emailSendClass.emailSendToContact(trigger.new, 'Contact Updated', 'You contact updated successfully');
    }
}

Thanks
let us know if it helps you​​

All Answers

shalushalu
this was unable to open this
send me another thing
sfdcMonkey.comsfdcMonkey.com
use this one :

http://www.sfdc99.com/2014/03/01/sending-emails-using-apex/

Thanks 
sfdcMonkey.comsfdcMonkey.com
else use following apex trigger and class code :

apex class :
public class emailSendClass {
    public static void emailSendToContact(List<contact> triggernew, string sSubject, string sBody){
         // Step 0: Create a master list to hold the emails we'll send
  List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
  
  for (Contact myContact : triggernew) {
    if (myContact.Email != null) {
      Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    
      // Step 2: Set list of people who should get the email
      List<String> sendTo = new List<String>();
      sendTo.add(myContact.Email);
      mail.setToAddresses(sendTo);
    
      // Step 3: Set who the email is sent from
      mail.setReplyTo('sirdavid@bankofnigeria.com');  //update it with your desired email 
      mail.setSenderDisplayName('Official Bank of Nigeria'); //update it with your desired Name 
     
      // (Optional) Set list of people who should be CC'ed
      List<String> ccTo = new List<String>();
      ccTo.add('test@gmail.com');
      mail.setCcAddresses(ccTo);

      // Step 4. Set email contents - you can use variables!
      mail.setSubject(sSubject);
      String body = 'Dear ' + myContact.LastName + ', ';
      body += sBody;
    
      mail.setHtmlBody(body);
    
      // Step 5. Add your email to the master list
      mails.add(mail);
    }
  }
  // Step 6: Send all emails in the master list
  Messaging.sendEmail(mails);
    }
}

trigger :
trigger sendEmail on Contact (after insert, after update) {
    if(trigger.isInsert && trigger.isAfter){
        emailSendClass.emailSendToContact(trigger.new, 'New Contact Created', 'You contact created successfully');
    }
    else if(trigger.isUpdate && trigger.isAfter){
        emailSendClass.emailSendToContact(trigger.new, 'Contact Updated', 'You contact updated successfully');
    }
}

Thanks
let us know if it helps you​​
This was selected as the best answer
shalushalu
thank you so much 
sfdcMonkey.comsfdcMonkey.com
welcome, if you got your answer then kindly close your query with selecting best answer so it will help others in future 
thanks
shalushalu
Is there any simple way coding  for this question
shalushalu
can u explain the above coding 
sfdcMonkey.comsfdcMonkey.com
see code comments & yes you can achieve it without single line of code : USE PROCESS BUILDER : check following post :
https://automationchampion.com/tag/sending-out-an-email-from-process-builder/

in short, create email tamplate and then use it on process builder 
thanks 
shalushalu
no it should use in trigger method only
shalushalu
there is any simple method coding for (if new contact is created send welcome email to that contact)this is an requirement using triggers
 
sfdcMonkey.comsfdcMonkey.com
than above code would sweet and short for your requirement
Thanks
shalushalu
if new contact is created send welcome email to that contact...i need this requirement coding 
shalushalu
create email template for both welcome email and update email