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
ClintLeeClintLee 

Displaying Image attachments in VF Page

Hello All,

 

I am trying to determine the best route for displaying image attachments on a VF Page.  

 

More specifically, I have an object called Site_Development__c which contains information about construction projects.  I would like for a user to be able to attach image files to the record (as attachments) which will then be displayed via a VF Page.  

 

Ideally I would like to create the VF page so that it could be inserted into the Site_Development__c page layout.  However, this requires using the Site_Development__c standard controller so I would need to create a controller extension and I am having trouble doing that.

 

Another option that I thought might be easier would be to create a VF page that simply displays all of the image attachments and then create a button on the Site Development page layout that links to this page.  However, I'm not certain if there is a simple way to display the images (like if I wanted to show the user's first name I could just do {!$User.firstname}).

 

Looking over some of the other posting I tried to patch together some code for an extension but I'm getting error messages saying invalid constructor.  

 

Extension (sorry in advance if the code looks weird, I always have trouble posting code in here)

 

public class SiteDevExtension {

private final tfgff__Site_Development__c siteDev;

public SiteDevExtension(ApexPages.StandardController stdController) {
this.siteDev = (tfgff__Site_Development__c)stdController.getRecord();
}

public List<Attachment> pics {get;set;}

public SiteDevPicDisplay() {
pics = [Select a.ParentId, a.Name From Attachment a where ParentId=System.currentPageReference().getParameters().get('id')];
}
}

 

 VF Page Snippet

 

 

<apex:repeat value="{!pics}" var="p">
{!URLFOR($Action.Attachment.Download, p.Id)}
</apex:repeat>

 

 Any feedback or recommendations would be greatly appreciated.

 

Thanks!

 

 

 

 

prageethprageeth

Hello Billyclint;

 

You gets InvalidConstructor error because your method doesn't have a return type.

 

public void SiteDevPicDisplay() {

 

pics = [Select a.ParentId, a.Name From Attachment a where

arentId=System.currentPageReference().getParameters().get('id')];

}