On Enterprise Edition: I have a custom link on the contact page layout that when clicked throws open a "Send an Email" edit page with several fields auto populated such as To, Subject, Email body, and even several attachments, for convenience.

Here's the URL coding for the button link:

/_ui/core/email/author/EmailAuthor? email_type=custom&template_id=00X50000001XtXB&**id=00Y5000000Ir7Kg**&p2_lkid={!Contact.Id}&rtype=003&retURL=%2F{!Contact.Id}

I believe the highlighted id above represents the email attachment(s) because the moment it is removed, the attachments don't appear. I got that id (among others) from Inspect Element on the email body when the email template is pulled from Send an Email -> Select Template.

Now, for some reason, this id=00Y5000000Ir7Kg does not permanently represent the attachments. It changes regularly in the last 5 characters. I later noticed this when all content but the attachments were pre-populated. At this point when I check the id, it is something like 00Y5000000 XyZAb.

This is the issue I'm facing. How do I pre-populate with URL coding, the attachment(s) effectively just like other fields are with no potential trouble?

Clarification: This id works for sometime in pre-populating the attachments; works for a day, two days, maybe even a week, but when this id changes thru some unknown action or for some reason, I have to manually update the URL code with this new id in order to continue pre-populating the attachments.

  • did you take a look at this post on how to form the URL : salesforce.stackexchange.com/questions/14819/… I see that you are adding &id=00Y5000000Ir7Kg (attachment Id's start with 00X I beleive) which is not required.Use /_ui/core/email/author/EmailAuthor?p2_lkid={!Contact.Id}&rtype=003&retURL=%2F{!Contact.Id}&template_id=00X50000001XtXB
    – Rao
    Commented Aug 1, 2013 at 23:20
  • are u open to visual force approach, making url param dependent function is less reliable and visualforce through a button gives u more room for improvement. If you dont mind vf route ill spin up something tonight.
    – Rao
    Commented Aug 2, 2013 at 2:44
  • let us continue this discussion in chat
    – Rao
    Commented Aug 2, 2013 at 3:25
  • @rao Please take a look at salesforce.stackexchange.com/questions/15384/…
    – Rosh
    Commented Aug 13, 2013 at 20:03

2 Answers 2


I would suggest the visualforce route just in case you find URL hacking not consistent. I am just Extending @sfdcfox answer in the above post :

Step 1: Copy paste this code save the page and controller before you start the button.

Step 2: Create a button on Contact and make it execute on javascript with the following code: window.open('apex/custom_button_contact?id={!Contact.Id}');

Do not change the page code:

<apex:page standardController="contact" extensions="custom_button_controller" action="{!sendEmail}">

Controller: When the user clicks the button take the contact Id and set it as targetobjectID ( target can be user or contact)

     public class custom_button_controller {

        string contact_id{get;set;}

            public custom_button_controller(ApexPages.StandardController controller) {
                contact_id = apexpages.currentpage().getparameters().get('id');

            public pagereference sendemail(){
                Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
//change the template ID to your own template ID
                    List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
//I have taken 2 random attachments you can do where ID=:'your attachment Id'
                    for (Attachment a : [select Name, Body, BodyLength from Attachment limit 2])
                      Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
                    Messaging.sendEmail(new Messaging.SingleEmailMessage[]{message});
                    return null;

  • Will implement this shortly and let you know how it goes. Thank you.
    – Rosh
    Commented Aug 2, 2013 at 6:22
  • @Rosh Did this route help you ?
    – Rao
    Commented Aug 2, 2013 at 16:39
  • @rosh i will look into this tomorrow morning and let you if i can help you out by tomorrow 12 pm PST
    – Rao
    Commented Aug 5, 2013 at 0:09
  • salesforce.stackexchange.com/questions/15384/…
    – Rosh
    Commented Aug 13, 2013 at 20:04

You should be able to have the attachments loaded as well if you add &new_template=1 in your original URL

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .