+ Start a Discussion
revathyrevathy 

Campaign object using for html email template ,but fields are not display in the email?

i have javascipt button "MassEmail" in campaign detail page,when we click the button send the email to all related campign members.In this purpose i have created one Html email template for campaign objects.But in email template i am not able display"detail page link".
========
Javascript code
==========
{!REQUIRESCRIPT('/soap/ajax/26.0/connection.js')} 
{!REQUIRESCRIPT('/js/functions.js')} 
{!REQUIRESCRIPT('/resource/Rfleet_JqyeryUI_STR/jquery1/js/jquery-1.8.3.js')} 
{!REQUIRESCRIPT('/resource/Rfleet_JqyeryUI_STR/jquery1/js/jquery-ui-1.9.2.custom.min.js')} 

var Contactids=[]; 
var recordname=[]; 
var emailids=[]; 
var contactname=[]; 

var CamMember=sforce.connection.query("SELECT CampaignId,ContactId FROM CampaignMember where CampaignId='{!Campaign.Id}'"); 
var records = CamMember.getArray("records"); 

for (var i=0; i<records.length; i++) { 
recordname = records[i]; 
Contactids.push(recordname.ContactId); 



var con=sforce.connection.query('SELECT Id,Email '+'FROM Contact where id in (\'' + Contactids.join('\',\'') + '\')'); 

var contactemail = con.getArray("records"); 

for (var i=0; i<contactemail.length; i++) { 
contactname = contactemail[i]; 
emailids.push(contactname.Id); 



for (var i=0; i<emailids.length; i++) { 

var message = new sforce.SingleEmailMessage(); 
message.replyTo = "rapsac@gmail.com"; 
message.targetObjectId=emailids[i]; 
message.templateId ="00X4E000000EMXt"; 
var result = sforce.connection.sendEmail([message]); 

if(result[0].success == 'true') { 
alert("I sent the email as you requested, master."); 
} else { 
alert("I had a booboo."); 
}
==========
email template
========
User-added image

Advanced thanks for helping:)
Best Answer chosen by revathy
Santhosh SSanthosh S
Hi revathy,

1) You need to set the whatid to Campaign.Id as mentioned below.
message.replyTo = "rapsac@gmail.com"; 
message.whatId ='{!Campaign.Id}'; 
message.targetObjectId=emailids[i]; 
message.templateId ="00X4E000000EMXt"; 


2) In the email template set the url with the Campaign Id variable as menioned below.User-added image



 if your question is answered, please choose 1 best answer. 

All Answers

Santhosh SSanthosh S
Hi revathy,

1) You need to set the whatid to Campaign.Id as mentioned below.
message.replyTo = "rapsac@gmail.com"; 
message.whatId ='{!Campaign.Id}'; 
message.targetObjectId=emailids[i]; 
message.templateId ="00X4E000000EMXt"; 


2) In the email template set the url with the Campaign Id variable as menioned below.User-added image



 if your question is answered, please choose 1 best answer. 
This was selected as the best answer
revathyrevathy
@Santhosh :thanks a lot,you saved my time.Its worked perfect