Admins

Salesforce Email URL Hack

By Ben McCarthy

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.

https://na15.salesforce.com/_ui/core/email/author/EmailAuthor?p3_lkid=006i000000QbrwP&retURL=%2F006i000000QbrwP

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.

_ui/core/email/author/EmailAuthor?

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.

/_ui/core/email/author/EmailAuthor?p3_lkid={!Opportunity.Id}&retURL={!Opportunity.Id}

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!

 

 

 

The Author

Ben McCarthy

Ben is the Founder of Salesforce Ben. He also works as a Non-Exec Director & Advisor for various companies within the Salesforce Ecosystem.

Comments:

    Garrett
    May 20, 2015 4:09 pm
    Thanks Ben, I'm trying to create a button to set both To and Related To fields. I've got my URL: /_ui/core/email/author/EmailAuthor?p2_lkid={!Enrollment__c.LeadId__c}&p3_lkid={!Enrollment__c.Id}&retURL={!Enrollment__c.Id} where: 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: https://cs7.salesforce.com/_ui/core/email/author/EmailAuthor?p2_lkid=00QM0000006isR1&p3_lkid=a1nM0000000c8YF&retURL=a1nM0000000c8YF 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.
    Garrett
    May 20, 2015 4:13 pm
    Let me add to that... I changed the button to: /_ui/core/email/author/EmailAuthor?p2={!Enrollment__c.Lead__c}&p3_lkid={!Enrollment__c.Id}&retURL={!Enrollment__c.Id} 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.
    Cindy
    March 08, 2016 8:53 am
    Hello Ben, Is there a way to add a confirmation message when user presses the 'Send' button in the 'Send Email' page? Thanks , Cindy
    sa
    April 13, 2016 7:09 am
    Hi, Is there any way to redirect from case detail view to Case feed view using formula hyperlink?
    shweta
    July 15, 2016 3:02 pm
    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?
    RebelPosts
    August 22, 2016 4:56 pm
    someone can hack email pls http://www.rebelposts.com/
    the real rebelpost
    August 24, 2016 2:04 pm
    wow someone really want to hack my site..
    Michael B
    September 26, 2016 9:47 pm
    I know I'm asking a lot of a URL hack, but can a parameter be added to select a "From" address?
    Kiran
    October 19, 2016 6:27 am
    I am also looking for the same. Did you find something?
    Mitesh S
    October 26, 2016 7:41 pm
    This works great in classic. Any clue how to get it working in Lightning for those 4 objects SF currently supports?
    Mike Walter
    January 25, 2017 10:29 pm
    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!
    Garrett Zaino
    January 26, 2017 12:57 pm
    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.
    Jos
    March 16, 2017 2:18 pm
    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.
    adultfrienffinder
    April 26, 2017 12:44 am
    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.
    Robby
    May 17, 2017 6:34 pm
    Having an issue where when I use this custom button, and I send the email, it reopens a blank email page instead of returning to the account. Can anyone help?
    Christian
    May 25, 2017 10:52 pm
    Thank you for this and your site !!! Awesome
    Michael Doss
    June 14, 2017 7:49 pm
    Is there a way to send emails from Salesforce using different from email "domains"? One email may be from x@.abc.com and another may come from y@xyz.com This would become super powerful for me.
    MMK
    June 15, 2017 11:30 pm
    Hi shweta, were you able to add a 'doc_Id' for url hack? If so, can you please share your solution?
    Ashlee
    June 20, 2017 4:06 pm
    Hello Ben, I have followed your tutorial and have created a button where the template and fields are populated as desired. My problem however, is that the template I have chosen to use has the required attachment that I want sent with this particular email and the attachment does not pull through when using the custom button even though the rest of the email template is displaying properly. I still have to go to Select Template from the send email page and select the template again to get the attachment to appear. Any ideas on how to make the attachment appear with the template automatically when clicking the custom button? Thanks!!
    Salesforce AG
    June 20, 2017 7:10 pm
    Hey Ben & Team, My code is below. I am trying to configure this button to send an email to only Lead Owner however the To: field keeps populating with the lead's email address. Is there anyway to override the To: field to just be blank without breaking the merge fields I have embedded in my email template? https://xxxxxxxxxxxxxxxx/_ui/core/email/author/EmailAuthor?rtype=00Q &p2_lkid={!Lead.Id} &retURL=%2F{!Lead.Id} &p5={!Lead.OwnerEmail} &template_id=00X1a000000hW5b
    Imran
    July 06, 2017 6:39 am
    Hello everyone, I have a requirement of send button. Can anyone please help me to create a send button in detail.. Thanks.
    Gil Levy
    July 20, 2017 10:05 am
    Thank you. Is it possible to determine the From: as well/ (from a selection of emails availble)
    MMK
    August 01, 2017 10:38 pm
    Thank you for posting this. I am using URL hack to open a prepopulated email page with recipients and attachments. In my url I do have retURL specified. But I am opening the standard SalesForce email page which means I have standard buttons that come with the standard SalesForce email page. Now when I send email with no attachments the retURL is works and I am shown the custom object page as expected . But when there is an attachment in the email, after sending this email the retURL does not work and it comes back to the email page again.
    Christina
    August 07, 2017 1:21 pm
    Hi Mitesh, Did you find a solution for this in lightning? To get the email to send automatically when clicking the button?
    neellima
    September 03, 2017 6:23 am
    Hi I created a custom button send email on custom object. on button click I want to populate sender, cc, bcc from custom object. and a template. Please help.
    angela mullen-smith
    September 04, 2017 9:34 am
    How do i add the attachments to the customer button. I tried adding the following below but the attachments are not attached to the email template &new_template=1 This is my code if( {!ISBLANK(Opportunity.Customer_Id__c)} ) { alert( "A customer must be created on IFS before a Quote can be raised. Request the creation of a new Customer on IFS!" ); } else { location.href = "/_ui/core/email/author/EmailAuthor?" + "&p3_lkid={!Opportunity.Id}" + "&p24={!Opportunity.Branch_Email__c }" + "&template_id=00X0O000001yrBa" + "&new_template=1" + "&retURL=/{!Opportunity.Id}"; }
    Ramesh Kalloori
    September 19, 2017 2:54 pm
    Hi Ben, I have created new custom button on vf page and i am navigating to send email link which you mentioned above with some parameters. My question is if we embed the send email link in vf custom button then the daily email limits will be reduced or not? Generally if we send email from contact that will not considered under email limits. Thanks, Ramesh
    Azmath
    November 23, 2017 12:40 pm
    Go to create->object->Sample Tracking custom object's page . Check the Track Activites checkbox and then try. If this solved your problem mark it as solved.
    Azmath
    November 23, 2017 12:43 pm
    when you get error The value of the "p3_lkid" parameter contains a character that is not allowed or the value exceeds the maximum allowed length.
    Aman
    December 21, 2017 11:53 am
    Thanks for this method, it works as expected.. However, does anyone know how to add the attachment in the mail automatically? Any option to do this is welcome.
    Maurizio
    January 13, 2018 3:24 pm
    In a custom button you can preset the sender email address specifying the parameter p26 in you URL: ....&p26=x@abc.com Obviously, the sender email address must be one of the admitteed ones.
    Mitesh S
    February 03, 2018 10:41 pm
    This is great and we have been using "doc_id" for pre-populating document. Now that Salesforce is supporting Files, any idea what is the URL parameter for that?
    Rich S
    March 07, 2018 1:11 am
    This is a very good article; however, when I'm using this with a case record, getting the p3_lkid field to populate the correct case #. I've tried using p3_lkid={!Case.ParentId} which worked the first time and all others attempts of the same case is showing the Account as the first value and the second blank. Here is the whole URL: https://scudderassoc.lightning.force.com/_ui/core/email/author/EmailAuthor?p2_lkid={!Case.ContactId}&rtype=003&p3_lkid={!Case.ParentId}&p6={!Case.Subject}&retURL=%2F{!Case.Id} Thanks
    Chau
    March 08, 2018 1:44 am
    Hi Salesforce AG, I have the same question. Have you figured out how to override the “To” field? Any recommendation would be really appreciated
    satya
    April 10, 2018 8:24 am
    I've gone through the entire article, is there any way to fetch the details from the saved email template to visualforce page to send it using an email client where we can add some of the customized content that varies from person to person.
    Garrett
    April 10, 2018 1:39 pm
    Hey Satya, It sounds like your requirement is similar to some of ours... * Leverage custom email client * Have Salesforce compose the template that looks good and its content (include merged data) * Allow users to customize messages Personally, I have not found a solution that meets all of the above. We are currently looking into the 'Send Email' button on activity history and seeing how that process works. There is a URL invoked when you select the template that retrieves the content and merges in the values - we will most likely use this with some javascript to pass the HTML to the body of a rich text editor to allow users to modify the content. This URL can be found on each template link after click the 'Select Template' button on the page launched from the 'Send Email' button on activity history. The URL parameters are pretty self-explanatory. Hopefully this gives some guidance.
    K.
    May 10, 2018 6:10 pm
    By the way, there's also a URLFOR that passes parameters a bit differently. Instead of: /_ui/core/email/author/EmailAuthor?p3_lkid={!Opportunity.Id}&retURL={!Opportunity.Id} You would say: {!URLFOR($Action.Activity.SendEmail, Opportunity.Id , [p3_lkid = !Opportunity.Id, rtype="003", retURL= "/" + Opportunity.Id])}
    Paula Kern
    June 07, 2018 3:02 pm
    I cannot get the "To Field" to populate. What am I missing. Here is my code: location.replace('/email/author/emailauthor.jsp?retURL=/{!Opportunity.Id}&p3_lkid={!Opportunity.Id}&rtype=003&template_id=00Xm0000000RfEe&p5=&save=1&p24=me@myemailaddress');
    David Sekules
    July 27, 2018 5:20 pm
    Hey Ashlee, I've set up a sweet link from a flow and have come across exactly the same issue: the Attachment only seems to come through if the template is selected using the button, not when it's defined in the URL. Did you ever find a way around this?
    Melissa Foley
    August 20, 2018 8:59 pm
    Hi Ben, I tried the first step and I'm receiving an error: URL No Longer exists. Any ideas? /_ui/core/email/author/EmailAuthor?
    Steve
    September 27, 2018 3:37 pm
    We've been doing something similar for years and have just come across something interesting. Passing through the email address in the p26 parameter might not be enough to guarantee success. When populating a picklist value through url hacking, you should pass through a value which exactly matches that of a select option. We've just noticed that the select option value parameters in field p26 on the EmailAuthor page aren't just the email address, but the email address AND the display name separated by a colon. So for example if you have an org-wide address of myemail@company.com, which has a display name of Test Email, you should set p26 to myemail@company.com:Test Email. Just passing the email does work, surprisingly, in selecting the correct email address but it changes the header values in the out-going email. We've just started getting spam blocked on some foreign servers and we found out this was the cause.
    Dan Ramirez
    November 26, 2018 9:38 pm
    I used this tutorial/hack to allow our users to start a new email thread, but we've found that they're unable to use the CC,BCC, Additional To lookups because it defaults to only show internal contacts (users). Has anyone found a way to do this with the Lightning interface? I've read that the issue we're running into is a classic limitation.
    Juan
    July 30, 2020 9:04 pm
    Hi Ben & all. Would you know if there is a way to apply an equivalent hack to this, but instead of navigating to a new page having the new Email Composer (lightning component) pop up? If you click on the Send Email action nowadays (in LEX), you get this new popup with a ton of functionality... but which you can't quite prepopulate in any way (so it takes additional clicks for the user to do very repetitive tasks). Thanks in advance for any insights!
    Falgun Atara
    November 26, 2020 4:54 am
    Hi, Is there any approach to use this Email Author URL for Salesforce Lightning Experience. Please let me know your thoughts. Thanks !!
    Melss
    November 05, 2022 6:30 pm
    Did you ever find a solution for this? While the URL hack works, the email template can't be modified in Lightning experience.

Leave a Reply