28 comments on “URL Hack Revisted: Auto Select Email Template With Custom Button

  1. This is the best article that I have found on this subject. This blows what is on the Salesforce forums out of the water, and is exactly what I was looking for. Thank you SO much.

    • Hi Vishal,

      Did you find any solution for :
      “when we pre-select email template and if the template has an attachment , the attachment is not populated”?

      I’m also facing that same issues.


  2. Hi,
    that’s a very cool idea, thanks.
    I looked into it and I’m wondering if there might be a way to modify the URL even further to automatically add an attachment from the document storage to the email.
    Do you have – by any chance – any idea if that’s possible?
    Thanks again,

    • Chris, I’m not 100% positive, but based on how the attachment system is setup I don’t think you can use a URL hack to add attachments only.

      You can add an attachment to an email template. So an option would be to use the URL Hack to set the template – which happens to have the attachment you want on it.

      • Hi,
        thanks for your quick reply.
        Shortly after I posted this question, I found the solution: If you want to add only one file (not sure how to do this for multiple files yet):

        Just add: &doc_id=DOC_STORAGE_ID

        DOC_STORAGE_ID is the ID in your SF document storage (prefix 015).
        That way, when the form is initialized, the attachment list is prepopulated with that document.

        Best regards,

  3. Hello, I have a component which I put in many VF pages (Contact,Account,Opportunity & custom object) in this component I have a button to send an email, with the /_ui/core/email/author/EmailAuthor…

    I set the parameters and the templateId
    (the template is a VF Template with component)

    I need to pass to the email template the ID of the page which the button is clicked from so
    if I in Contact – I need the contactId
    if in Accout the account ID
    if in Opportunity the OppId
    etc… (with custom objects)

    with p2_lkid, I can pass the contactId , but that’s not enough for other Objects

    How can I pass the ID which can be changed depends from where I click the Send Email button?

    Here is my email template:

    {! recipient.Name}
    {! recipient.Id}

    Thank you very much for any help and guidance

  4. This was a very helpful post. I modified my hack so that it would send an email to our internal atty with all the relevant opp fields “merged” into the email, so she can start a legal review process. The hack pre-addresses to the atty, so our saleperson clicks the button, and then Sends –


  5. Use case: Case page layout (using feeds) replace the default “Email” publisher action so that some case information is automatically populated in the email (like adding the case number and subject to the email subject etc). Is this possible?

    • Julian,

      I haven’t tried to override the default email publisher action. I’m not sure it is even feasible at this time. If you still wanted to use a regular publisher action, you’ll have to create a custom one using Visualforce and Apex. A URL Hack won’t help you on this one.

  6. OK, I am new with SF.com and I have set up customized buttons that point to a full URL in the past and it works well. I’ve not tried it to point to a page within SF.com before. I have constructed the URL that I need, but how do I append it to the SF.com instance that I am using? In other words, when you have the URL like the one in this article, how do you pass the html that comes before the “/”?


    Thanks for the article.

    • Paul,

      You don’t have to specify the sf.com instance. As a matter of fact you shouldn’t!

      It’s a standard that if the server (instance) isn’t denoted in the URL then the browser assumes the page is on the same server as the button that calls it.

      This way that button will work regardless if you click it in production or sandbox.

    • Oops, never mind. I see that all you have to do is put in everything after the “/” and don’t worry about whats in front. It works fine.

      Thanks again.

  7. Dear Mr. Wizard, I have been struggling with a problem which has led me here. Maybe you can help.

    Every Opportunity is linked to a Campaign (we call them Projects). So when an email is sent from an Opportunity, I want that Campaign Name to be inserted into the Email Activity record. I have created a custom Activity lookup field to contain this value. This gives me:


    This does not work. I have also tried substituting the actual campaign name (i.e. “USCG15”) for {!Opportunity.CampaignId} and that also does not work.

    This seems so simple but I have never been able to save a value in the Activity custom field. Any thoughts?

  8. Pingback: Happy New Year/Anniversary: Don’t Call It a Clip Post | Wizard & Friends News

  9. I’m trying to have multiple email addresses from the record appear in the “Additional To:” field. I can get one to appear using the p24 code, but to add others (all field references on the record) I’ve tried separating with commas, repeating the p24= several times, and can’t seem to get it to work.

    Do you have a solution?

    • Perhaps you can use %0D to insert a CR after each email address:


      I’ve not tested this but the URL reference says %0D is a CR. You might also need to add %0A for a LF. Just a guess, hope it helps.

  10. This is a great explanation. I’m using this to send an email off a Solution record, but I needed a few other fields to update along with the email which I have done. Problem is if the user clicks Cancel, the changes I have set still get applied. Any way to prevent this?

      • I’m sorry to say you’re out of luck if you want to have changes -> Email.

        You could look at using the URL hack to get the email template. When sent, it’ll create a task on the related record. You could then use Process Builder and flow to update the record – if you know what the changes are. Or you could put a Flow URL as the retURL so the user goes to the Flow when completing the email and the flow takes the user’s input to update the record. You still run into the situation where they could simply not complete the flow. Only thing I can think of is you could have the flow’s first action update a field not on the page layout and then use a validation rule that shows an error if the user tries to update the record without your required fields filled in.

        This is all a stretch and it really depends on the specific changes you’re trying to capture. URL Hacks are really a short cut to manual changes. They’re not a good replacement for a workflow process.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s