Salesforce Email URL Hack

Following on from my 4 Clever Hacks with Custom Buttons post, I’m going to be covering URL Hacking with Salesforce Emails. What this will allow you to do is override the default function of that “Send Email” button in Salesforce to do whatever you want! Pre-populate a standardized subject for cases, pre-populate a template for lead qualification, the world’s your oyster!

If you are unsure what URL Hacking is, I would recommend you skim through my URL Hacking Tutorial as a pre-requisite just to get an idea how it works.

Step 1 – Creating the Button

Lets start by creating the basic button for this solution. If you click on a “Send Email” button on Salesforce you will see a URL similar to the one below, I’m using Opportunities for this demonstration.

If you have read over my URL Hacking Tutorial you may be able to decipher this yourself, although it is a bit different. You can se at the start we have our normal Salesforce URL with a _ui/core/email etc… then a couple of parameters and their values. These parameters and their values work a lot like our values in the URL Hacking tutorial, but they are fields on the email page. For example the p3_lkid= is filling in the “Related To” field, to make sure this email is stored against the record we launched it from. The retURL parameter you may find familiar, this is the Return URL (Or ID) if we press cancel during the operation, we will be brought back to the original record.

But for this part of the tutorial, we are interested in this part.


Create a button similar to mine below. Add it to the page layout and click on it. If working correctly, this should launch a blank email page.

Screen Shot 2015-02-09 at 12.13.29

Step 2 – Adding parameters

Now we’ve got our button working, all we need to do is add in some parameters. These are the parameters that are available to you.

p3_lkid – Related To
retURL – Return URL if cancel is pressed
p2_lkid – To (Contact or Lead ID)
p4 – CC
p5 – BCC
p6 – Subject
p23- Email Body
p24 – Additional To
template_id – Salesforce Email Template ID

As a prerequisite I would always add in p3_lkid and retURL as these will always be needed.


Once we have our basis we can add as many parameters as we like to automate this button! Remember to always add an & between parameters to separate them.

Step 3 – Automating it a step further with Formula Fields

If you want to further automate your button not with fixed values, but with values that change depending on the account or situation. We can bring formula fields into this.

Lets say your a global organisation with customers from all over the world. As you’re nice, you would like to send lead qualification emails in your customers native language. We could create 10 different buttons associated with 10 different Salesforce Email templates, OR we could create 1 button, associated with a formula field that picks the correct template based on a bunch of parameters.

Once you have created your templates you need a formula field on your associated object with either a CASE or IF statement, like the below.

CASE( Account.BillingCountry , “France”, “00Xi0000000NPgA”, “United Kingdom”, “00Xi0000000NPgF”,”00Xi0000000NPgF”)

Once added we can check this is working by adding it to the page layout, we can then merge this formula field into the &template_id= parameter and bingo!




Subscribe To The Monthly Newsletter

No Spam. No Rubbish. Just great content from the Salesforce Industry.

You have Successfully Subscribed!

14 thoughts on “Salesforce Email URL Hack

  1. Thanks Ben,

    I’m trying to create a button to set both To and Related To fields.

    I’ve got my URL:

    Enrollment__c is the object we are sending the message from
    LeadId__c is the Id of the parent lead of the Enrollment – this is a lookup field

    The button generates the following example URL:

    The problem is I get an error when I click it. I’ve noticed the error shows up only when I have both the p2 and p3 parameters. Any idea? Here’s the error:

    Unable to Access Page
    The value of a parameter contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and resubmit. If the error still persists, report it to our Customer Support team. Provide the URL of the page you were requesting as well as any other related information.

    1. Let me add to that…

      I changed the button to:

      which set the Leads full name as the p2 parameter, I also tried this with p2_lkid, and the page rendered without error however no parameter passed in. I’m thinking it’s something to do with both To and Related To have an ID passed through the parameter.

  2. Hello Ben,

    Is there a way to add a confirmation message when user presses the ‘Send’ button in the ‘Send Email’ page?

    Thanks ,

  3. Hello Ben,

    Can we add a document to the attachments in the email template?
    Where do I save the visualforce page as PDF so that it can be used as the ‘doc_id’ for Url hack?

  4. This works great in classic. Any clue how to get it working in Lightning for those 4 objects SF currently supports?

  5. Hello, is there a way to select which Contact email address I would like to send to using the p2_lkid function? We have a number of email addresses stored under the Contact record, some of which are related to the contact, but not the contacts, can we select that address to send to? Thanks in advance!

    1. Hey Mike – the way emails are stored are as activities, which to my knowledge always uses the Related to for the “To” line of the email header. Because of this, I don’t believe there is a way to pass a straight email address. That said there are a couple suggestions you might find useful:

      1. Leverage the “CC” and “BCC” lines to insert the email address you wish to send to directly. I believe you still need to link the contact (I haven’t verified), which would mean the contact your target email is stored on will receive the email as well.

      2. Update the information you are storing on the contact to a Lookup and reference the contact directly. This should allow you to update the formula of the URL hack to reference the email address through the parent lookup – therefore setting the related contact in the “To” line of your email.

      Hope that helps.

  6. Hi Ben,

    I’m very close in working this out in combination with a support language on the case however i’m getting a generic error using the following URL on the button.

    /email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&CASE({!Case.SupportLanguage__c},”English”,template_id=00X7E000000OzGd, “Dutch”,template_id=00X7E000000OzIe)&p26={!Case.SupportEmail__c}

    Will you be able to spot the error here ? It would be great if this would work.

  7. Admiring the time and energy you put into your blog and
    detailed information you present. It’s awesome to come across a blog every once in a while that isn’t the same outdated
    rehashed information. Excellent read! I’ve bookmarked your site
    and I’m including your RSS feeds to my Google account.

Add Comment