Hello folks, In this tutorial, I am going to create a Trigger on Lead to Send Email to Contact on Lead Conversion.

Lead Trigger to Send Email to Contact on Lead Conversion:

 

trigger LeadTrigger on Lead (after update) {

Set < Id > setContactIds = new Set < Id >();
List< Messaging.SingleEmailMessage> lstEmail=new List< Messaging.SingleEmailMessage>();
for ( Lead objLead : trigger.new ) {

/* Getting Contact Ids from the Lead after conversion .
ConvertedContactId in Lead contains the Contact Id to which the Lead is converted.
*/
if ( objLead.IsConverted && objLead.IsConverted != trigger.oldMap.get( objLead.Id ).IsConverted )
setContactIds.add( objLead.ConvertedContactId );

}

if ( setContactIds.size() > 0 ) { 


for ( Contact objCon : [ SELECT Id, Name,Email FROM Contact WHERE Id IN: setContactIds ] ) {


Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
mail.setToAddresses(new String[]{objCon.Email});
mail.setReplyTo( 'vinodpalne@gmail.com' );
mail.setSenderDisplayName( 'Salesforce Support' );
mail.setSubject( 'Contact Is created after Leade Conversion ' + objCon.Name );
mail.setHtmlBody( 'The new Lead is converted.' ); 
lstEmail.add( mail );



}

Messaging.sendEmail( lstEmail );

}
}

 

Output:

Debug On Web