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
Maxi SMaxi S 

How to display image present in notes & attachment related list using VF page

1) Created one custom object
2) Addded one image file under Notes & Attachment related list
3) Want to display this image in visual force page
KaranrajKaranraj
Maxi - Follow the below steps and code sample for displaying attachment image in the Visualforce page.

1. Get the Attachment record ID and append in this URL - /servlet/servlet.FileDownload?file= 
2. Use that url string in the visualforce <apex:image> tag to disaply the image in visualforce page

Apex Controller Class:
public with sharing class ImageController {
 public String imageURL{get;set;}
   
  public ImageController()
  {
    imageURL='/servlet/servlet.FileDownload?file=';
    List< Attachment> AttachmentList=[select Id from Attachment where Name='sample.PNG'];
   
    if(AttachmentList.size()>0)
    {
      imageURL=imageURL+AttachmentList[0].id;
    }
  }
}

Visualforce Page:
<apex:page controller="ImageController" showheader="true" sidebar="true">
 <apex:form >
      <apex:image url="{!imageURL}">
    </apex:image></apex:form> 
</apex:page>

Thanks,
Karanraj

 
Maxi SMaxi S
Thanks much Virendra & Karanraj !!