So, some background. I have created a visualforce page that displays a Case and renders it as a PDF. This works fine. I have included it on a Case Page Layout as a Detail Button and it correctly formats all the information when clicked.

I have now created a second Visualforce page that uses the standard case controller and a new extension class. This is intended to email a recipient with the PDF page above attached. I have added it to the page layout as a detail button and in my tests or if I run it via salesforce classic it works.

However our Org uses the Service Cloud Console and I want to load this functionality from there. Obviously the page layout contains the button so I click it, I enter the email address and click send (I can see the case controller is working as the page displays the casenumber etc). On receipt of the email I always receive an unformatted/broken/blank PDF document and for the life of me I don't know why.

Can anyone shed any light as to why it would work in my tests but not in the console?

Thanks - I haven't included my code above as it seems to be working if you think it would help I can copy the code in.

EDIT: Attachment code below:

public with sharing class PDFEmailController {
    private final Case cs;
    public String caseID {get;set;}
    public String email {get;set;}

    public PDFEmailController(ApexPages.StandardController controller) {
        this.cs = (Case)controller.getRecord();

     public PageReference sendPdf() {

    PageReference pdf = Page.PDFPAGE123;
    // add parent id to the parameters for standardcontroller
    // the contents of the attachment from the pdf
    Blob body;

    try {

      // returns the output of the page as a PDF
      body = pdf.getContent();

    // need to pass unit test -- current bug  
    } catch (VisualforceException e) {
      body = Blob.valueOf('Some Text');

    Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
    attach.Body = body;

    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    mail.setToAddresses(new String[] { email });
    mail.setSubject('PDF TESTING');
    mail.setHtmlBody('<p>Please see attached</p>');
    mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach }); 

    // Send the email
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,  cs.CaseNumber + ' with PDF sent to '+email));

    return null;


Edit - as comment, I changed it to getContentAsPDF() and this returns an almost blank PDF document (it only lists the visualforce page and controller with an x on the right hand side).

  • Yeah I think we'll at least need to see the code you use to generate the attachment.
    – Adrian Larson
    Jan 28, 2017 at 22:00
  • I've copied the apex class in for you - thanks for letting me know.
    – n34_panda
    Jan 28, 2017 at 22:03
  • It seems like the getContentAsPDF() method may be more appropriate here...
    – Adrian Larson
    Jan 28, 2017 at 22:05
  • Thanks, that does let me open the PDF but I simply get a single line that state "th ename of the PDF visualforce page and it 'sextension class in one word" if you know what I mean. I am about switch debug logs on to see if that brings anything up
    – n34_panda
    Jan 28, 2017 at 22:11
  • Forgive me for asking, it maybe unrelated but could it be this: success.salesforce.com/issues_view?id=a1p300000008bkjAAA
    – n34_panda
    Jan 28, 2017 at 22:45

1 Answer 1


Rather hilariously the problem was quite simple - I needed to disable "Development Mode" for my user.

  • Click "User Name"
  • Click "My Settings"
  • Click "Personal"
  • Click "Advanced User Details"
  • Untick "Development Mode"

You must log in to answer this question.

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