function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Quick-Email button: using it within an Opportunity

Relating to the article titled The Quick Email Button in the Service & Support Blog of Successforce, I had the following query:

I'm trying to co-opt what Marco Casalaina did for a Case to create a link for an Opportunity.  I'm calling it "quick close email" which, as planned, will allow a rep to pull up our closing email template with one click from the Opportunity page. The syntax I am using follows:

location.replace('/email/author/emailauthor.jsp—retURL=/{!Opportunity.Id}&p3_lkid={!Opportunity.Id}&rtype=003&p2_lkid={!ContactId}&template_id=<your template here>');

Where "your template here" is the 15-character ID for the email template I would like to use.

Unfortunately, there's something wrong with the command -- it returns an "Unable to Access Page" message when launched from the opportunity. Doubly unfortunately, I know nothing about javascripts, so I can't troubleshoot this on my own. Any clues for me? Thx!
Well, let's see.

Your merge field is wrong, for one.  Opportunity has no {!ContactId}, nor does it have the properly formatted version, {!Contact.Id} -- opportunity has a
separate Contact Roles table.  If you have made a custom field that is a lookup to Contact then you could use that, but by default opportunity has no
direct Contact field.

Did you in fact put a template ID in the <your template ID here> or are you actually using that verbatim?  If your URL really says <your template ID here>
then that won't work, you have to put a real template ID there per the instructions on the blog.
Looks like I'll have to create a custom field that is a lookup to Contact.  Or perhaps I could just use the Contact Roles (primary contact) in the same way.  I'll toy with that.  My problem is understanding the syntax, not understanding the concepts.  And yes, I did actually use the 15-digit template ID, not the <your template ID here> text.

Thanks, Werewolf. 
If you want to use Contact Roles you'll have to query on the primary contact and plug it in rather than using the merge fields -- at least, I don't think there's a merge field for the primary contact of an opportunity.
Hi Werewolf,

I'm trying to use also the Quick Email Button.
I have implemented it and it works just fine,
the only thing I would like to modify is the "To" recipient and I can't seem to find how to do it.
Do you have any clue?

Thank you in advance for your help,

Would you be so kind as to copy the text of your javascript into the discussion here?  I don't understand the syntax well enough to make it work, as easy as it should be.  It sounds like your attempt worked... I'm a newbie, and would appreciate the help.  Thanks!
Hello Werewolf,

I'm trying to do the same thing within a Lead... here is my javascript:


Since Leads don't have a contact ID, I'm not sure what should go there instead... Can you help me please?

For leads, you want to emulate what the Send An Email button does when you press it from a lead.  That means get rid of the p3 parameters and only use the p2_lkid, and set it ti {!Lead.Id}.  And the rtype will be 00Q.
Thanks for your response... Did I intrepret you correctly (sorry, I don't really know Java) here:


It still isn't working... =(
Well, for one, you have to take the < and > off of the template ID.
Werewolf, you are WONDERFUL - thank you!!!
Hello Werewolf,

I'm trying do to the same thing, but as a Detail Page Link instead, but it isn't working... can you help again, please?


As a detail page link you have to either get rid of the location.replace and just put the URL there (it may have to be fully qualified with an http:// and so on), or leave the location.replace and put a javascript: in front of it.  What you were doing before was JavaScript – what you're doing now is a straight-up HTML link.  That's the difference.
It didn't work as a URL so I tried to make it a button using the same javascript as above, but that didn't work either.
Is it possible to create a Quick-Email button to email the owner of a Contact?  I'd like for the users to be able to email the owner of a contact easily to request permissions to the contact, etc.
You can, but not by URL-hacking the send an email page.  You'd have to use the sendEmail API verb instead.
:smileysad:Here's the time when I have to admit to having no clue how to do this.  Can you possibly direct me to a help page or article?  Thank you very much for your response.
The sendEmail example in this doc would be a good start:
Thank you!  I'll check it out immediately.

Hi all,

Thanks for all the contributions to this thread - in leiu of a user's guide on url parameters it is a great help!


I am trying to do basically the same thing as everyone else here, with one caveat I can't compensate for.


I want to send the email to an address that is stored in a custom field on a record (I know, it should be a contact lookup but it's not for a very good reason which I won't get into here.)


So I have set up my url as follows:


And I think the issues lies in the p2_lkid={!Marketing_Request__c.RequestorEmial} as this is NOT a contact ID.
Is there a parameter I can set that is the toaddress, not a contact id from which Salesforce gets the email address?
Thanks, any info would be great.
BTW Is there a guide to parameters anywhere??? I can't find one!

Message Edited by Ems on 09-09-2008 02:18 PM
Ron WildRon Wild

Posting parameters to EmailAuthor is not supported by Salesforce, so no, there is no documentation on the parameters it will accept.  You'll have to deduce this by inspecting the page and pages that call it using tools like Web Developer for Firefox that show the form field names.  Some have posted their findings here and and on blogs.  Try Googling EmailAuthor.


On a closely related topic, I found that Visualforce email templates with visualforce attachments require an additional parameter:




So a full custom link might look like:





Without "new_template" the email template will appear, but not the visualforce attachments.


Hope that helps someone out there.



I'm trying to create a visualforce page to replace the emailauthor page. Any way to use the standard button functionality in this visualforce page (i.e. send, select template, attach file, etc)?

Good luck with that.  You're going to have a very hard time getting it to resolve an email template and make it editable before you send it out. 


To your question, no, you'll have to write your own buttons (although while you're at it maybe you can make the attachment button inherit attachments from the parent object, which it currently doesn't do).


Hi all-


I found very helpful, but now am trying to take it a little further... I have the below for sending an email from a Lead record...




This works great, but I don't want the 'To' entry to populate. The problem is that if I remove 'p2_lkd={!Lead.Id}', then the Lead merge fields in my email template do not populate.  Is there a way the merge fields can pull from the Lead record, but not poplulate the 'To'.  Ultimately I would like a button to email the Lead information to someone else.


Thanks in advance...


FYI- Chirag post here is also helpful if have not seen -


hello, I finally found the solution! :robothappy:

you have to add  the parameter "p3_lkid= {!Lead.Id}"


this is my button:








Thank you, Fra08!  Copying that code solved my Lead email template/custom button woes.


is there any way to dynamically select the template using a few nested IF statements?





I hope this thread is not dead.  I just created a Quick Email button using Werewolf's code.  I want the email to go to the record/case creator (Created By).  Based on the code I have, it goes to the case owner.  Can someone help me identify what needs to change in the code below.  Admittedly not a Java Girl.  Other than this, the button works perfectly...just going to the wrong person.  Here is my button: