• Clara Prom
  • NEWBIE
  • 0 Points
  • Member since 2021
  • Altosaxo

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
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.


Message Edited by GlennAtAppirio on 02-18-2007 01:05 PM

Message Edited by GlennAtAppirio on 02-18-2007 01:05 PM