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

Creating a button to send template email to contact

Hi - hopefully a simple question.


I'm trying to create a custom button to send a template email to the lead.


I've found some relevant board posts but they all seem for more complicated uses - I'm simply looking for a button that would mimic the following:


Activity:Send An Email

Select Template

[template id]



Does that make sense?  I'm familiar with how to create buttons, I just can't figure out the syntax.   


Well, you can create a custom button and put the source as OnClickJS!

You just need to redirect the user to the send mail page with the template loaded-


As you can see, you need the template ID to pre-load it on the page and you can pass additional parameters too if you want to in the URL itself!

In case, you want to send the mail automatically, then you need to write some apex code in the backend and execute that in an S-Control/VF page which will be attached to this custom button. You can refer to the apex docs for the syntax of how to send an email through apex code.


Message Edited by Cool_Devloper on 11-22-2009 09:56 PM


I am trying to figure out how to use your example.  Can you break down what is included in your URL?

 Also is there a SF document that explains this?


For example:


how do i know what the different parameters are, and which other ones can i use?


What is p2_lkid=003S000000XXXXX

What is &rtype=003

what is &p3_lkid=500S000000XXXXX

what is  &

what is  template_id=00X700000015WDiEAM   - this is the email template id i think.

did you ever figure it out i'm having the same issue?

Check this link-






Here is a custom URL hack that I just did and it works.


Base URL: 

p2_lkid={object ID}Who we are sending it to

&rtype=003 = Not sure what this is

&p3_lkid={object ID}What we are relating this to

&template_id=00X80000001Ehde = put your template ID here

&saveURL=%2F{object ID}


Replace all the red stuff with your variables.  I think you pretty much have to hardcode the template ID, but no biggie.


Set the button behavior to: Display in existing window without sidebar or header

and the Content Source to URL


Add it to your page layout and  voila!  Magic button that sends out the email template you want, and logs the activity.  


I can't, however, seem to make this set the Task type to 'Email'  But this was pretty easy. Give it a try!


Question - What if i dont want to use an object ID for teh 'Who we are sending to' but I want to specify the to address as interalteam@xyzcompany.


I've used this button technique to send emails but the user has to select the to from a a dummy account. I'd rather not do that if I can simpy hard type it.


Found the answer: I used the p24 value and it worked fine, add the =save1 at the end of the url and the user never has to even see the email.


Just so you know. The _lkid is meant for instances where you are passing an SFDC ID. Like in a lookup field.

x = John Smith
x_lkid = 0036000001HC

The x will fill in the visible text in the look up field. The x_lkid will pass the record ID so that SFDC can create the correct relationship. 

Let me know if this makes sense.


Javier I got it.
Thanks for your answers.
I dropped the _lkid and just used the p24= .

So for multiple users use comma with no space to separate addresses?

Thaanks again.


Mitesh SuraMitesh Sura
Unfortunately this will not work in Lightning. Anyone with a solution? 
Stefaan SomersStefaan Somers
We also use this solution, but sometimes have issues with it. If you talk to Salesforce support, they tell you that they don't support this combination of javascript & URL hack. They don't provide an alternative solution either. 
sekhar maramreddysekhar maramreddy
the logic to send an email once click that button to respective contact