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
PSCRPSCR 

Auto populate 'To' field on 'Send an Email' page when a particular template is selected.

Hi All,

I have a custom object (Sub__c) which has a lookup relationship to Contact. I have 'Send an Email' button in Activity History related list on the custom object record's detail page. When I click 'Send an Email' button, 'Send an Email' edit page will be displayed. Now, when I select a particular template, the field 'To' should auto populate with the contact name. 

Please let me know how to achieve this. Thanks!User-added image
NagendraNagendra (Salesforce Developers) 
Hi PSCR,

Please find the sample code below for similar issue and modify the code as per your requirement which allows you to surpass the challenge.
Please try this in Contacts Custom Button.  (Select Display Type = "Detail Page Button" and Behavior = "Execute JavaScript".)
 
location.replace('/email/author/emailauthor.jsp?retURL=/{!Contact.Id}&rtype=003&p2_lkid={!Contact.Id}&template_id=00Xi00000012xit&p24=sample@g.com&p4=sample2@g.com&p5=');
 
Below is a list of parameters definitions:
 
template_id = id of email template you want to pre-populate
email_type=visualforce (if the template that you're using is a VF email template)
new_template=1   = required if you're using a VF email template that contains an attachment
p2_lkid = id of the record for the To address (a Contact, Lead, or User Id)
rttype = the id prefix for the type of the To address (e.g., if p2_lkid refers to a Contact, use rttype=003)
p3_lkid = id of the record for the Related To (i.e., What) record (e.g., an Account or Opportunity)
p4 = CC address
p5 =  BCC address
p6 = Email subject
p7 = Email body
p24 = Additional To
p26 = From address
doc_id = the id of a Document or QuoteDocument to become an email attachment
retURL = URL to return to after the email is sent
cancelURL = URL to return to if the user clicks Cancel
For more information check here: Please mark this as best answer if the information helps.

Best Regards,
Nagendra.P

 
PSCRPSCR
Hi Nagendra, thanks for your response. I think, if we create a custom button with the above code, when we click that button on the record detail page, then 'To' field is getting auto-populated and email template is also selected automatically.
 
But my requirement is- I have a lot of email templates in the system. If I select a particular email template called 'ABC', only then the 'To' field must be auto-populated.
sam sjsam sj
Hi,  Did you find any solution for the requirement of autopopulating "To" field when Template is selected ? Thanks in advance.
Sarah FazekasSarah Fazekas
I have the same question - if you solved it I would love to know how. Thanks!
Ujwala pATIL 13Ujwala pATIL 13
Hi , I am having the similar requirement, I need to auto populate cc field based on the email template I select. Did you find any solution for ablove requirement? It would be great if you share the same. Thanks !!
Marymol MijeshMarymol Mijesh
Hi, I have the same requirment. I need to populate to address feild based on the template selected. Did you find any solution for autopopulating?