Tell me more ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I am trying to select the appropriate email template using javascript on a custom button. Here is a stripped down version of my code:

var template; 
var type = "{!My_Custom_Object__c.My_Field__c}"; 
if(type == "Quick") { 
template = "00XV0000000DlRB"; 
}
location.replace('/email/author/emailauthor.jsp?p3_lkid={!My_Custom_Object__c.Id}&[email protected]&p5=&template_id=template')

If I replace the end of the last line with template_id=00XV0000000DlRB, it works; but if I use the variable template, it says template_id contains a character that is not allowed. Any ideas? Thanks.

share|improve this question

1 Answer

up vote 2 down vote accepted

template is a varible, so you should concatenate it to literal string by using "+".

 '...emplate_id='+template

Try this:

var template='';
if("{!My_Custom_Object__c.My_Field__c}" == "Quick") { 
   template = "&template_id=00XV0000000DlRB"; 
}
location.replace('/email/author/emailauthor.jsp?p3_lkid={!My_Custom_Object__c.Id}&[email protected]'+template)
share|improve this answer
Thanks. I'm confused by the "'" before the plus. Is that syntax correct? – JimH Jun 17 at 19:04
the quotes were justo to highlight the symbol. you only have to concatenate doing: "your-url"+valiable – Martin Borthiry Jun 17 at 19:08
Got it. It worked. Thanks. – JimH Jun 17 at 19:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.