+ Start a Discussion
Amit BanAmit Ban 

how to send HTML Email Template in custom lead object email id?

I have created a custom object Lead__c and it has a email field. I need  to send a standard HTML email Template in Lead__c object's email Id using a custom button "send company profile".

Is there any way to achieve this? 



 
Best Answer chosen by Amit Ban
Murali MattaMurali Matta
Hi Amit,

Try below code.
 
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/31.0/apex.js")}
var message = new sforce.SingleEmailMessage(); 

message.targetObjectId = "{!Lead__c.Id}";
message.toAddresses = "{!Lead__c.Email}";// In email place use Email Field
message.templateId = "00Xq0000000HwSw"; // Copy Standard HTML email Template
message.whatId = "{!Lead__c.Id}"; 

var result = sforce.connection.sendEmail([message]); 
if(result[0].success == 'true') 
{ 
    alert("Email sent successfully"); 
} else 
{ 
    alert("Sending failed"); 
} 
alert(result);

Let me know if you have any confusion.

Kindly mark this as solved if the reply was helpful.

Thanks,
Murali

All Answers

Murali MattaMurali Matta
Hi Amit,

Try below code.
 
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/31.0/apex.js")}
var message = new sforce.SingleEmailMessage(); 

message.targetObjectId = "{!Lead__c.Id}";
message.toAddresses = "{!Lead__c.Email}";// In email place use Email Field
message.templateId = "00Xq0000000HwSw"; // Copy Standard HTML email Template
message.whatId = "{!Lead__c.Id}"; 

var result = sforce.connection.sendEmail([message]); 
if(result[0].success == 'true') 
{ 
    alert("Email sent successfully"); 
} else 
{ 
    alert("Sending failed"); 
} 
alert(result);

Let me know if you have any confusion.

Kindly mark this as solved if the reply was helpful.

Thanks,
Murali
This was selected as the best answer
Raj VakatiRaj Vakati
You can do ut by using the Visual force page and call the send email logic in apex class 

https://developer.salesforce.com/forums/?id=906F0000000DDszIAG

 
public void SendEmail()
{
 List<contact> lstcon=[Select id from contact limit 2];
 List<Id> lstids= new List<Id>();
 for(Contact c:lstcon)
 {
  lstids.add(c.id);
 }
 EmailTemplate et=[Select id from EmailTemplate where name = 'EmailTemplatename' limit 1];
 
 Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
 mail.setTargetObjectIds(lstIds);
 mail.setSenderDisplayName('System Admin');
 mail.setTemplateId(et.id);
 Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });
}

 
Amit BanAmit Ban
Thank you, everyone.