Wednesday, May 15, 2013

The Quick Email Button

...or, mastering the black art of URL hacking the email page.
Sending an email from can be a clicky operation.  You dig around for the Send An Email button, click it, click Select Template, find your template and click it, maybe type some more stuff in the email, and finally click Send.  That's a lot of clicks, especially for organizations where they just use the same template over and over.  Well, the good news is that you can make this a much less clicky operation by making a custom button which changes the URL parameters.  Technically URL-hacking is not supported by, and it's technically not a supported API, so be forewarned -- but when you're on a quest to reduce clicks, you gotta do what you gotta do.
So let's say you have a template that you usually use for Cases which contains some pleasantries and then a merge field that adds in the text of any related Solutions.  If you've not used Email Templates much before, by the way, have a look at the sample template entitled "SUPPORT: Case Response with Solution (SAMPLE)" --  it does just what I've described here.  Anyway, what you'll want to do is make a custom button that preselects this template.  It's quite simple really.
  • The first thing you'll need to do is get the ID of the template you want to use.  This can be found by finding the template via Setup->Communication Templates->Email Templates.  Click on it and look in the URL -- you'll see an ID up there that looks like 00X30000000rNM0 (which may be followed by a ? with some other parameters -- ignore that stuff, just take the 15-character ID that starts with 00X).  Copy that ID into Notepad or someplace where you can get to it later.
  • Now go to Case and create a Custom Button -- let's call it Email Solution.  Set its Behavior to Execute Javascript and its Display Type to Detail Page Button.  In the Javascript area add this line of code, replacing the <your template here> with the ID of the template you saved earlier:   location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=<your template here>');
  • Now add this custom button to your Case page layout, and voila, you have a one-click button that will bring up your email complete with template.

But wait, there's more!

To this we can actually add a few more bells and whistles.
By default the Send An Email page likes to BCC the sender.  Many call center agents I talk to find this rather annoying.  With the addition of another URL parameter to our custom button, we can stop it from BCCing anyone.  The parameter is p5, so our new code would be:

author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=<your template here>&p5=');
Notice at the end there the "&p5=" -- that sets the BCC area to empty.

But what if you just want to send the email in one click with no edits?

Well, you can do that too, with -- you guessed it -- one more URL parameter: the save parameter.  If I take the above code and add a save=1 to it, then when I click the button, the email will just be sent, and the Case page will refresh itself to indicate that an email was sent:

author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=<yourtemplate here>&p5=&save=1');

Note that this parameter only works for long-established orgs -- for new orgs the save=1 parameter is disabled for security reasons.  If you have a newer org (created in 2010 or later) then you should use the AJAX Toolkit to send the email.  That will be the subject of a future blog post here.

What if you want to add some email addresses to Additional To?

Easy enough, that's p24.

And what if you want to change the From address?

You may have noticed that if you have Email To Case enabled with some routing addresses, or if you've modified the email address in the My Email Settings page in the Personal Information area of Setup, that when you go to send an email you have a choice of From addresses.  You can default this From address too!

The From address is just another parameter in the URL -- it's p26.  So taking our earlier example, let's add a From address default:

author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=<yourtemplate here>&');

Note that the p26 default will only work for items that are actually in that From address list.
And that ends today's lesson on email buttons.  

Happy emailing!


  1. This comment has been removed by the author.

  2. Hi,

    Is it possible to modify default FROM according to different Record Type?
    I mean, if i have Record type X the from should be X.
    If Record type is Y the from should be Y.

    Thank you