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
Ishan K SharmaIshan K Sharma 

Display notes and attachments in VF page


I have word docx file in notes and attachments. I want to display it in my vf page. Is there any way to do this.



Ishan Sharma


Hello Ishan,


You can include related list in the VF like:


<apex:relatedList subject="ParentObjectId" list="NotesAndAttachments"/>

Ishan K SharmaIshan K Sharma

I dont want to show list. I want to show content in the list on my vf page.

for ex if my attachment is pdf file so i want to show whole pdf on my vf page.





Use the link I pointed you at - basically you point at the download servlet for the attachment, and if the browser has a plugin that can display it, it will use that.

Ishan K SharmaIshan K Sharma

Bob thanks for the help but i need little more. I am able to display the
pdf content  now with help of above link but there is one more prob.
My vf page is pdf type(renderas = 'pdf'). Now if i remove this renderas
attribute then i am able to display my attachments but if i add renderas
="pdf" then i am not able to display it. Is there any solution for this.
*My vf page is also pdf type. *


When you say display the attachments, is that rendering the attachments related list or actually displaying the body of an attachment?

Ishan K SharmaIshan K Sharma
Display body of attachment..

*I want to display whole body of attachment(pdf) in my vf page which is
also pdf type(renderas).*

I doubt you'll be able to do that.  The problem is that the browser will pull the contents of the servlet and use that when rendering the page.  Once you are into a PDF plugin, that won't know what to do with that markup.  I suspect you'd need to find a way to render your attachment body as HTML.

Nikhil ArpallyNikhil Arpally
Hi Ishan,
Did you find any solution for displaying the pdf attachment on VF page while rendering as PDF? Even I am facing the same problem that you have mentioned above.
Ishan K SharmaIshan K Sharma
it is not possible. You have to create nested vf pages. You have to open vf page which is rendering as pdf into a normal vf page. otherwise you need to merge to pdfs and open it as one, in this case you need to fetch the data from sf objects only and you cannot do it directly from notes and attachments
Ankit Arora 30Ankit Arora 30

I want to convert VF to PDF and then save it to Notes and attachments and below are the VF pages and apex class.

When I run the process, a pdf is created successfully at the right location under the Custom__c but its blank. When I "login to community as a user", again the same vf page is blank but when I create a custom link of vf page in Custom__c object, I see the entire letter in pdf. Before putting the extension and action tag, I was able to see the same page from the custom link and from "login to community as a user". Can you please tell me what I am doing wrong, why its showing blank page.
Also VF page render the output dynamically, its not a static page.
Please help me.

1st Visualforce Page: (Letter)
<apex:page standardcontroller="Custom__c" extensions="attachPDFToCustom" action="{!attachPDF}" standardStylesheets="false" showHeader="false" applyHtmlTag="false" applyBodyTag="false" docType="html-5.0" >
<apex:include pageName="Letter_V2"/>

2nd Visualforce Page: (Letter_V2)
<apex:page renderAs="pdf"> </apex:page>

Apex Class:
public class attachPDFToCustom {

public attachPDFToCustom(ApexPages.StandardController standardPageController) {
public void attachPDF() {
PageReference pdfPage = Page.Letter_V2;
Attachment attach = new Attachment();
Blob pdfBlob;
      try {
             pdfBlob = pdfPage.getContent();
       catch (VisualforceException e) {
             pdfBlob = Blob.valueOf('Some Text');
attach.parentId = ApexPages.currentPage().getParameters().get('id');
attach.Name = 'Letter - '+ system.Now() + ' .pdf';
attach.body = pdfBlob;
insert attach;

Thank you