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
Sami ShakithSami Shakith 

Email template as a lookup field


I want to get email template as a field in custom object(using lookup relationship). Is it possible? If it is how can i?
Kanika DuaKanika Dua
Hi Sami,

You can not get Email Template as Lookup field on Custom Object.But You can get it on as Lookup Field in  VF page using a wrapper class

This blog works out for me

Hope this helps

Best Regards
Kanika Dua
Sami ShakithSami Shakith
Thank you Kanika Dua. It helps me.

Sami ShakithSami Shakith
Hi kanika,

This is for list of records. Can we do it for single record?
Kanika DuaKanika Dua
Hi Sami,

It means you don't want your user to Select from a List of Templates.You just want an single Template

Correct me if I am wrong
Sami ShakithSami Shakith
Yes i need a single template for a user. But It should be lookup field. That means Selecting template from list of templates.
Kanika DuaKanika Dua
Hi Sami,

Thats what Exactly happening their.You will get a List of templates from Lookup and Then You will select one by Clicking on particular Template Name.Selected Templated Name comes in Box and Id comes in Variable
Sami ShakithSami Shakith
Hi Kanika,

Actually it is displaying in the form of table. I tried to remove the table and display as a single record(not list of records), but email template onload window is not opening.
User-added image
I need a single row without using pageBlockTable

User-added image

Here is my controller class and VF page
public class CustomLookupPageController {
    public emailTemplateWrapper record{get;set;}
    public CustomLookupPageController (){
        record=new emailTemplateWrapper(0);
    public class emailTemplateWrapper{
       public String emailTemplateName{get;set;} 
       public String emailTemplateId{get;set;}
       public integer counter{get;set;} //to store rowindex
       public emailTemplateWrapper( integer count){
<apex:page controller="CustomLookupPageController" id="wpage">
<script type="text/javascript">
var templatenameid;
function openTemplatePopUp1(field){
    var rowindex=anchortagid.substring(9,10);
   if (field != null) {
        field.href = "JavaScript:openLookup('/_ui/common/data/LookupPage?lkfm=editPage&lknm='+templatenameid+'&lkrf=&epf=1&lktp=00X',670,'1','&lksrch=' + escapeUTF(getElementByIdCS(templatenameid).value.substring(0, 80)))";
<apex:form id="form1">
   <apex:pageBlock title="Custom lookup" id="pgb1">
       <apex:pageblockSection id="pgbks1" columns="2">
           <apex:pageblockSectionItem id="pgbsi1">
              <apex:outputPanel id="pgbt1">
                   <apex:inputhidden value="{!record.emailTemplateId}" id="Template_lkid1" />                 
                   <apex:inputhidden value="{!record.emailTemplateName}" id="Template_lkold1" /> 
                   <span class="lookupInput"> 
                       <apex:inputText value="{!record.emailTemplateName}" onchange="getElementByIdCS('wpage:form1:pgb1:pgbks1:pgbsi1:pgbt1:{!record.counter}:Template_lkid1').value=''; " id="Template"/>
                       <a title="Email Template Lookup (New Window)" tabindex="4" onclick="setLastMousePosition(event),openTemplatePopUp1(this)" id="Template_{!record.counter}_lkwgt" >
                          <img title="Email Template Lookup (New Window)" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onblur="this.className = 'lookupIcon';" class="lookupIcon" alt="Email Template Lookup (New Window)" src="/s.gif" />

Kanika DuaKanika Dua
I copy pasted your code and only one lookup is visible.Maybe You can test it in a diffrent browser
User-added image
Sami ShakithSami Shakith
Functionality not working. Have you checked the functions?