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
Ram ParitalaRam Paritala 

i want to send an email by clicking "sendemail" button in a standard page. how can i acheive this ??

NagendraNagendra (Salesforce Developers) 
Hi Ram,

May I request you please elaborate your requirement so that we can understand better and can help you accordingly.

Assuming,

For example, we are working on a standard lead object and you want to open a specific e-mail template pre-filled with the Lead's name and e-mail address so that you can then send the e-mail to the Lead's e-mail. 

If your requirement is something similar to the above then the below code should do the trick.

Step1:

Create an Apex Class with the following code.
public class testemail
{
private final Contact con;
public testemail(ApexPages.StandardController controller)
{
this.con=(Contact)controller.getRecord();
}

public void SendEmail()
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId(con.Id);
mail.setTemplateId('00X90000000QHUD');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Mention a valid Email Template ID in the colored part...


Step 2:

Create a VF page named as "testemail" or anything as your wish, and paste the code below.
<apex:page standardcontroller="Contact" extensions="testemail">
<apex:form>
<apex:commandButton value="Send Email!" action="{!SendEmail}"/>
</apex:form>
</apex:page>

Step 3:
 
Go to the URL bar and type
Note that make sure you mention a valid contact ID of your SF instance.

Please let us know if you are looking anything else other than this.

Happy to help further.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra