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

How to send VisualForce report as an attachment to external users

I have a PDF report that is created using Visualforce . Please let me know if It is possible to send this report as an attachment to external users.

It would be helpful if code is provided.


consider ur page name is testpage 


then write a controller logic to get the page content as pdf using the below code..but just to make you aware, u can't  use getContentAsPDF in 

  • Triggers
  • Scheduled Apex
  • Batch jobs
  • Test methods
  • Apex email services


PageReference pageRef = page.testpage;

blob b = pageRef.getContentAsPDF();

Attachment attachment = new Attachment();
  attachment.Body = b;
  attachment.Name = 'test.txt';
  attachment.ParentId = accountId; 
  insert attachment;

I was able to send email with attachment.When i try to open the attachment ,i am getting message as 'Adobe reader cannot open xxx.pdf because it is neither a supported file type or because the file has been damaged'.