2

I need to display attachments on a visual force page for the Case object.

This is the code I am using. I had it working for awhile, but it somehow broke down. It gets all the attachments, but it will not show the images.

<apex:repeat value="{!Case.attachments}" var="att">
            <apex:panelgrid columns="1">
                <h1>Image/h1>
                <apex:image url="/servlet/servlet.FileDownload?file={!att.Id}"/>
            </apex:panelgrid>
</apex:repeat>
2

Try using this :

<apex:repeat value="{!Case.attachments}" var="att">
            <apex:panelgrid columns="1">
                <h1>Image/h1>
                <apex:image url="{!URLFOR($Action.Attachment.Download, att.id)}"/>
            </apex:panelgrid>
</apex:repeat>

Let me know if it works for you. Thanks

2
        <apex:repeat value="{!Case.Attachments}" var="att">
            <apex:panelgrid>
                <apex:image styleClass="vitality-check-img" url="{!URLFOR($Action.Attachment.Download, att)}" rendered="true"/>
            </apex:panelgrid>
        </apex:repeat>
1

Looks like you want to display the files so the users can download them. Instead of using apex:image, do this:

<apex:outputLink value="/{!att.Id}" target="_blank">View File</apex:outputLink>

This ensures to display all kinds of file, be it pdf or jpeg or text. Let me know if it works for you.

  • No, the attachments need to be viewed on the page, not download links. Otherwise it would be practical to just add the attachment related list to the page @heisenberg – TemporaryFix Jun 4 '15 at 18:23
  • I think you should remove this "/servlet/servlet.FileDownload?file=" and pass the att Id only. Have you tried this? - <apex:image value="/{!att.Id}"/> – the_phantom Jun 4 '15 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.