1

I have a custom object related to an Account and Contact which has a custom button which launches a VF PDF page showing some of the object's fields in a format more appropriate for customers to see. So far so good. The goal is to send this PDF as an attachment to a Contact. Easy enough:

  public void emailPDF(Id id){
     //the id parameter would be the object's id
     PageReference pdf new PageReference('/apex/PDFReport');
     pdf.getParameters().put('id',id);
     pdf.setRedirect(true);
     Blob blobOfPdf = pdf.getContent();
     Messaging.EmailFileAttachment attch = new Messaging.EmailFileAttachment();
    attch.setBody(blobOfPdf);
    //set file name create email, set addresses set attachment etc.
  }

Originally I was going to construct a button with a link to a VF page that has a text area to enter the body of the email or choose templates and then send the email and redirect to the custom objects page; however some of the sales reps would prefer to use Outlook to format the email and enter the body of the text etc.

I'm wondering if there is a way I can create the attachment, grab the applicable outgoing address, blind copy address to log the email in Activity, and any templates and then open this as a new email within Outlook for the reps to edit or add to before sending the email.

1

There are ways to open Outlook. In my experience, these methods are not reliable. You'll run into so many configuration issues with different machines and such that you'll regret having ever opened this can of worms.

If you want to accommodate these users, create a compromise by either:

  1. Allowing them to paste their HTML from Outlook into your HTML Body and send the email from Salesforce.
  2. Generate the PDF and let them attach it to the Outlook Email manually. You could do this by attaching it to the Custom Object, the Account Record or another place of your choosing.
  • This is what I was afraid of. Thanks for the advice. However since I'm a glutton for punishment, how might I start going down this road? – Josh D Jan 5 '17 at 14:23
  • Take a look at the headers on Outlook emails that you've received which were successful vs ones that didn't come thru to see what's missing. – crmprogdev Jan 5 '17 at 14:31

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.