You need to sign in to do that
Don't have an account?
GlennAtAppirio
Sending A Template-Based Email From an S-Control
These boards have numerous threads about sending emails from s-controls. Having just wrestled with a variant of the problem for a customer, I thought I'd post the solution I used, which (now!) seems fairly straightforward (although it took some bobbing & weaving to get here).
Problem Statement: With one click, allow a user to create an object, then send a template-based email to a Contact associated with that object. The email template must populate with correct values from the just-created object.
Solution: Save the following code as an s-control snippet. Then include the snippet, and call the function from anywhere in your main s-control. (I won't cover the part about creating a new object here - let's assume you can do that, and then retrieve the object ID of your newly created object.)
function sendEmail(templateId, contactIdForToAddress, relatedObjectId) {
var url = "https://na3.salesforce.com/email/author/emailauthor.jsp?";
url += "p2_lkid=" + contactIdForToAddress;
url += "&p3_lkid=" + relatedObjectId;
url += "&template_id=" + templateId;
url += "&new_template=1";
url += "&retURL=%2F" + relatedObjectId;
url += "&nosave=0"; // not sure what this parameter does, or if it's really needed
url += "&save=1"; // send it now - don't just bring us to the "send email" page
window.open(url);
}
The net effect here is that a new window (actually, a tab in Firefox) will open up, pointing at the newly created object. If it has an Activity History related list, the just-sent email will appear there.
This all worked rather elegantly for me. The actual use case is a Google Map showing the location of various Communities (a custom object). The user can select several Communities (from a sidebar with a list of accounts & checkboxes), then click a single button to create "Referrals" (a custom object) to each selected Community, and email each Community's primary contact with their Referral data. After the click, the user waits a moment, and then multiple tabs open up, one for each newly-created Referral.
I'm happy to discuss further if anyone is interested or needs help doing something similar - glenn@appirio.com.
Problem Statement: With one click, allow a user to create an object, then send a template-based email to a Contact associated with that object. The email template must populate with correct values from the just-created object.
Solution: Save the following code as an s-control snippet. Then include the snippet, and call the function from anywhere in your main s-control. (I won't cover the part about creating a new object here - let's assume you can do that, and then retrieve the object ID of your newly created object.)
function sendEmail(templateId, contactIdForToAddress, relatedObjectId) {
var url = "https://na3.salesforce.com/email/author/emailauthor.jsp?";
url += "p2_lkid=" + contactIdForToAddress;
url += "&p3_lkid=" + relatedObjectId;
url += "&template_id=" + templateId;
url += "&new_template=1";
url += "&retURL=%2F" + relatedObjectId;
url += "&nosave=0"; // not sure what this parameter does, or if it's really needed
url += "&save=1"; // send it now - don't just bring us to the "send email" page
window.open(url);
}
The net effect here is that a new window (actually, a tab in Firefox) will open up, pointing at the newly created object. If it has an Activity History related list, the just-sent email will appear there.
This all worked rather elegantly for me. The actual use case is a Google Map showing the location of various Communities (a custom object). The user can select several Communities (from a sidebar with a list of accounts & checkboxes), then click a single button to create "Referrals" (a custom object) to each selected Community, and email each Community's primary contact with their Referral data. After the click, the user waits a moment, and then multiple tabs open up, one for each newly-created Referral.
I'm happy to discuss further if anyone is interested or needs help doing something similar - glenn@appirio.com.
Message Edited by GlennAtAppirio on 02-18-2007 01:05 PM
Message Edited by GlennAtAppirio on 02-18-2007 01:05 PM
When the user saves the new custom object, I want a new email to be composed (but not sent yet) using a template, and related to the custom object that was just saved. I also want to pull in the contact field from that custom object, as well as up to 5 email addresses from 5 email address fields in the custom object.
It seems that I need to add some procedure to the "save url" part of my original custom button URL, but when I do that it doesn't use the template or pull in any custom fields. Could I run an S-control from the "Save URL" parameter of my URL to do this? If so, how do I run an S-control from the SaveURL part of a URL, and what would my S-Control need to contain.
I appreciate any advice, code, or links to other posts to help me tackle this.
Thank you.
All Answers
Here's a slight variation of what Glenn has posted. In this case, I have a button s-control that launches a jump screen where the user fills out a little form that determines and looks up who the email should be going to including some additional to and cc addresses. Then it calls the email form and leaves them looking at the edit screen rather than firing the email silently. The idea is that the user can add some additional verbiage before the final send if they wish to. Here's the send email function:
Code:
JT Lovell
jt_at_appirio.com
Ambili
Message Edited by JT Lovell on 10-26-2007 01:49 PM
You should use the Send Email API instead of calling the URL. Sample code is available here
http://wiki.apexdevnet.com/index.php/Send_Emails_Through_SControls
Hi Rasmus,
Thanks a lot for your response! This is exactly what I have been hunting... for sending dynamic emails from S-control without having to rely on templates. I tried it and it works perfectly.
Thanks again for your timely help.
Regards,
Ambili
For example related objects fields ?
Thanks in advance
When the user saves the new custom object, I want a new email to be composed (but not sent yet) using a template, and related to the custom object that was just saved. I also want to pull in the contact field from that custom object, as well as up to 5 email addresses from 5 email address fields in the custom object.
It seems that I need to add some procedure to the "save url" part of my original custom button URL, but when I do that it doesn't use the template or pull in any custom fields. Could I run an S-control from the "Save URL" parameter of my URL to do this? If so, how do I run an S-control from the SaveURL part of a URL, and what would my S-Control need to contain.
I appreciate any advice, code, or links to other posts to help me tackle this.
Thank you.
Before Winter 09, here is the technique I used :
- Create email template in Salesforce from word document (with copy/paste)
- Take the HTML code generated to inject it in emailauthor.jsp
- Delete email template (I use it only to help the html code generation)
The HTML code is not very clean but it works well and it's quick.
Dropkick Murphys (https://altosaxo.net/products/dropkick-murphys-t-shirt-mens)
Galneryus (https://altosaxo.net/products/galneryus-t-shirt-mens)
Heavens to Betsy (https://altosaxo.net/products/heavens-to-betsy-band-t-shirt-ladies)
Thanks a lot for your response! This is exactly what I have been hunting... for sending dynamic emails from S-control without having to rely on templates. I tried it and it works perfectly.
Thanks again for your timely help.
Regards,
Asktop10 Asktop10Asktop10Asktop10Asktop10Asktop10Asktop10Asktop10Asktop10Asktop10Asktop10Asktop10Asktop10Asktop10Asktop10Asktop10Asktop10Asktop10Asktop10 (https://www.asktop10.com/)