In Blog, Tips & Tricks

In my previous post, Great URL Hack, Meet The Chatter Publisher Action, I talked how we can replace URL Hacks in Salesforce with the Chatter Publisher Action. I also mentioned the URL hack still has it’s place in the Salesforce Administrator’s toolbox.

Let’s take a look at an example. I like to call this my “Guided Send Email” button. This custom button will take the user to the “Send an Email” page, select the Email template, and populate the “Additional To” field. Before we begin, this is a URL hack (I’m sorry Shannon Hale ). It’s not an officially supported feature by Salesforce.com and it may break in the future.

The Use Case

We have the need for our Sales users to send an email to a specific address. The email needs to contain some information, some which can be pulled directly from the Opportunity. We need to make this as simple as possible for adoption purposes.

We already have an email template created. It’s a HTML template  that has merge fields to pull in the Opportunity information and a series of questions for the Owner to complete.

So the process normally will be to:

  1. Go to the Opportunity
  2. Scroll down to the Activity History area
  3. Click the “Send an Email” button
  4. Click “Select Template”
  5. Select the Template Folder
  6. Select the template
  7. Fill in the “Additional To:” field with an Email address
  8. Answer Questions
  9. Click the “Send” button

It’s not a terribly complicated process. We can improve it. We’re going to reduce that to 4 steps:

  1. Go to the Opportunity
  2. Click “Request Specialist”
  3. Answer Questions
  4. Click the “Send” button

Let’s do this!

Let’s look at the page we’re taken to when we click “Send an Email” from the Opportunity page. Here’s the URL:

https://na2.salesforce.com/core/email/author/EmailAuthor?rtype=003&p3_lkid=0064000000SInUR&retURL=%2F0064000000SInUR

This is great. The button is already using URL parameters. That’s basically everything you see after the ? in the URL. Each parameter is a key value pair. That means each parameter name needs a value. It looks like: ParameterName=ParameterValue. In our URL sample, are parameters are:

  • rtype –“Type” for the Related To
  • p3_lkid – Related To ID (Opportunity)
  • retURL – return URL (Where the page goes, for example when you click Cancel)

So we first need to reduplicate this URL. We  grab everything after Salesforce.com/ and add on from there.

  1. /_ui/core/email/author/EmailAuthor?
  2. rtype=003
  3. p3_lkid={!Opportunity.Id}
  4. retURL=/{!Opportunity.Id}

Now we can add to it. We need to find the names of the fields in the source of the HTML. For brevity purposes I’m just going to list the fields we’re going to use below. To see how you can get the HTML of your pages check this article.

  • p2_lkid – To/Contact ID
  • p4 – CC
  • p5 – BCC
  • p6 – Subject
  • p23 – Email Body
  • p24 – Additional To
  • template_id – Email Template ID

For my URL, we’re going to use a email address in the “Additional To” field and select the email template. So I have to new parameters:

  • p24=Reporters@WizardNews.com
  • template_id=00X40000001XQwz

/_ui/core/email/author/EmailAuthor?rtype=003&p3_lkid={!Opportunity.Id}&retURL=/{!Opportunity.Id}&p24=Reporters@WizardNews.com&template_id=00X40000001XQwz

There it is! Now we just need to put that in our custom button,that button on the page layout, and we’ve successfully removed 5 steps for our Sales folks. I don’t recommend you go crazy creating buttons for every email template. That would make your page ugly and not very user friendly. Here’s some ideas for other ways you can use this URL hack.

  1. Finish Location for a Visual Workflow. I’m really looking for a chance to try this out. I could use Visual Workflow to collect all the information I want a user to include in an email. I could even use visual workflow to route users to different email templates or change the recipients based on decisions within the flow. This could be a great option for situations where you want to guide the user to the result, but don’t need to store the answers in Salesforce. Plus, you still have the option to save some of the information in your Salesforce record if you need to.
  2. Request Support Link on Side Bar. Personally, I rather have a link to a flow and end up with a case in Salesforce than a series of emails. To each their own! You would need to make some changes since we won’t be linking to an Opportunity, but you could have to select a template and fill in the recipients.
  3. Case Email that includes Knowledge Article I love that we can create email templates that will attach the knowledge article to an email. Sometimes that’s all you really need. This could be a link or button on the Case to help your staff send out the articles faster. Double bonus points if you embed it into a visual Flow that will update the case fields, close the case, and then take the user to the Send Email page.

What other ideas do you have for using this type of URL Hack? I’ll love to hear them in the comments!

Recommended Posts
Showing 48 comments
  • morpheus pratiksha
    Reply

    wizard news a good compaigning company

  • Ashley
    Reply

    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.

  • VISHAL VERMA
    Reply

    That is a very good solution ,but when we pre-select email template and if the template has an attachment , the attachment is not populated.

    • Salesforce Wizard
      Reply

      Thanks for the comment. I haven’t experienced that. I’ll do some testing and try it

    • Rajendra Rathore
      Reply

      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.

      Thanks

  • Chris
    Reply

    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

    • Salesforce Wizard
      Reply

      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.

      • Chris
        Reply

        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,
        Chris

        • Salesforce Wizard
          Reply

          very cool! I’ll have to give that a try. Thanks for sharing it Chris!

        • Jon
          Reply

          Chris,
          This is great stuff…..thanks for sharing. By chance did you ever figure out how to add multiple files? I’ve tried a variety of things without any success. Thanks ahead of time for any and all input.

  • Ronen
    Reply

    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

  • Rob Kaplan
    Reply

    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 –

    /_ui/core/email/author/EmailAuthor?rtype=003
    &retURL=%2F{!Opportunity.Id}
    &p2_lkid=003G0000021Osnd
    &p3_lkid={!Opportunity.Id}
    &p5={!$User.Email}
    &template_id=00XG0000001sUal

  • dellastreet58
    Reply

    Tremendous help. Exactly what I needed. Thanks!!!!!

  • Julian
    Reply

    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?

    • Salesforce Wizard
      Reply

      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.

  • Paul
    Reply

    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 “/”?

    /_ui/core/email/author/EmailAuthor?rtype=003&p3_lkid={!Opportunity.Id}&retURL=/{!Opportunity.Id}&p24=Reporters@WizardNews.com&template_id=00X40000001XQwz

    Thanks for the article.

    • Salesforce Wizard
      Reply

      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.

    • Paul
      Reply

      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.

  • John Madden
    Reply

    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:

    /_ui/core/email/author/EmailAuthor?rtype=003
    &p2_lkid={!Account.Id}
    &p3_lkid={!Opportunity.Id}
    &CF00N50000003UvxS={!Opportunity.CampaignId}
    &retURL=/{!Opportunity.Id}

    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?

  • Peter
    Reply

    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?

    • John Madden
      Reply

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

      ?p24=joe@abc.com%0Dmike@abc.com%0Djim@abc.com

      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.

      • Kirsten
        Reply

        This is works so great.

  • staci gilmore
    Reply

    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?

    • Salesforce Wizard
      Reply

      Staci, so you only want the changes to the record to occur when the email is actually sent?

      • staci gilmore
        Reply

        yes

        • Salesforce Wizard
          Reply

          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.

  • Gaurish
    Reply

    “template_id” parameter is not working

    • Brian Kwong
      Reply

      what does your URL look like? template_id does work – just re-tested to make sure it didn’t get killed in Spring ’15. So there must be something else going on.

      For example, is the email template available for use? Are you grabbing the right ID for your template_id?

  • Rachita
    Reply

    Thanks for the great blog. I have a query. The retURL is used when user clicks on the Cancel button. but when user clicks on Send then it takes to the view page. I want that like Cancel button, the send should also take me to the retURL that i have given in my url. Let me know if this is poss or not.

  • Cindy
    Reply

    Hi Brian, Is there a way to add a confirmation message when user clicks on ‘Send’ button in ‘Send Email page’? Thanks

  • Cindy
    Reply

    Hi Brian, is there a way to add a confirmation message when user clicks on ‘Send’ button in send email page? Thanks

    • Brian Kwong
      Reply

      Cindy,

      You lose all control once you’re on the page where you can select a template and put the recipients in. You COULD use a javascript button that takes the user to the send email page and have that pop up a confirmation message. Alternatively, you could create your own send e-mail page using visualforce where you’ll have ultimate control.

      Also note that URL Hacks like this and Javascript buttons don’t work in the new Lightning Experience UI.

  • Chris
    Reply

    Did you end up getting this to work for the Flow Finish Location?

    • Brian Kwong
      Reply

      I did. Unfortunately it was at a different company so I don’t have the example on hand. it also required a visualforce page since I was referencing information from the Flow

  • Andreas
    Reply

    Hi Mr Wizard, thanks so MUCH for the great tutorial. Is there a way to have multiple p24 values? (e.g. {!User.Email},distro@domain.com

  • Andreas
    Reply

    So, I SOLVED the “multiple values” per &p24: you can actually delimit with a “,” e.g. &p24=wizard@domain.com,wizardpupil@domain.com,wizardpupil2@domain.com&template_id=00X40000001XQwz

    HOWEVER, is there any hack for forcing the “From” Email to be the active User’s (user clicking the button) email to be the sender, even if the UI displays the “verified” emails?

  • Fatima
    Reply

    Hi all,

    just to share that I was facing the same problem to attach multiple attachments with the help of url hacking. So I found one solution for this. Thought to share it here so others can have a complete solution on this post 😉

    Just add “&new_template=1” as another parameter in url and it will attach files related to the email template to the related list of attachments on email screen.

    Hope that helps

  • Abinesh anandhan
    Reply

    How to populate two field values for P6 parameter in send email custom button.
    like window.parent.location.href=”/_ui/core/email/author/EmailAuthor?p6={!URLENCODE(Case.Subject)} and i have to add one more field value (Leave ID)

    • Brian Kwong
      Reply

      Since you’re during a URLEncode you could just do something like {!URLEnCode(Case.Subject Case.Type)} and let the encode handle dealing with the space (%20) or any other special characters you put in there.

  • Laura Burnett
    Reply

    Hello, thanks for this. Is it possible to have two related objects in an email template? Use case:

    – I work for an events company, and we are looking to send emails to our event attendees, with their logistical information
    – This info needs to be pulled from two child objects (hotel booking & transfer booking) and one parent object (event attendee)
    – I can use the link hacking to get the information from the hotel booking & event attendee object (as this is the parent) but not the transfer booking
    – We don’t have enough relationship formulas available to push the information onto the event attendee, and don’t really want to start using workflows to update fields

    Thanks!

    Laura

    • Laura Burnett
      Reply

      Also, additional question, is there a way to use link hacking to get the sent email to trigger a process or workflow? I know you can redirect the return URL to a flow URL, but that seems messy as even if the email cancels the flow would trigger. We want to stamp the email sent date on the record to report off of, but the process is not triggered unless you go back into the task & edit/save it, as the task record is created by an internal process.

      • Brian Kwong
        Reply

        Hi Laura,

        First if you want to send info from multiple objects in an email template you have a couple of options. The first is to create a field on the parent object that has the details you want in the email. Then reference that email. You used to be able to have a text area with HTML code in and then pull that into a Custom HTML email template and have the HTML code from the field rendered. I’ve heard conflicting reports on that working or not.

        Alternatively, you can create a visualforce email template which will be more flexible but does require coding.

        Regarding your other question about triggering automation. Process builder, triggers, and workflow only fire upon a record being created or edited. When you use the send email button it should create a task record. So you COULD fire automation from the task being created. It’s tricky because it’s not the record that the email is spawning (for example the contact). So if you wanted to grab information based on that contact record or update related Account of something like that, you MUST use flow in order to use the WhatID (related to on the task) to go query the object. Process Builder and Workflow won’t do that. You could use Process Builder to ID the task being created and then use Flow as the action to handle everything else. An apex trigger would also be an option.

        Keep in mind these URL hacks are not officially supported and will not work in the Salesforce Lightning Experience UI.

  • Mitesh S
    Reply

    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?

    • Brian Kwong
      Reply

      Not a clue. Since this style if hack doesn’t work with lightning experience, I haven’t even tried to update it for files. My guess is that it doesn’t work

pingbacks / trackbacks

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.