2

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 Aug 1 '13 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 Aug 2 '13 at 2:44
  • let us continue this discussion in chat – Rao Aug 2 '13 at 3:25
  • @rao Please take a look at salesforce.stackexchange.com/questions/15384/… – Rosh Aug 13 '13 at 20:03
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}">
</apex:page>   

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
        message.setTemplateId('00Xd0000000Lfp0');
                    message.setTargetObjectId(contact_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();
                      efa.setFileName(a.Name);
                      efa.setBody(a.Body);
                      fileAttachments.add(efa);
                    }
                    message.setFileAttachments(fileAttachments);
                    Messaging.sendEmail(new Messaging.SingleEmailMessage[]{message});
                    return null;
                }

            }
  • Will implement this shortly and let you know how it goes. Thank you. – Rosh Aug 2 '13 at 6:22
  • @Rosh Did this route help you ? – Rao Aug 2 '13 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 Aug 5 '13 at 0:09
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.