2

I would like to display an image attachment on my visualforce page (via standard controllers).

What I would like to add is a render statement to only show this the attachment exists? Right now the page shows an error if there isnt any images attached to the record.

Apex

<apex:image url="{!URLFOR($Action.Attachment.Download, News__c.Attachments[0].Id)}" styleClass="img-responsive"></apex:image>
1

Use the rendered attribute.

<apex:image url="{!URLFOR($Action.Attachment.Download, News__c.Attachments[0].Id)}" styleClass="img-responsive" rendered="{!News__c.Attachments.Size>0}"!></apex:image>
| improve this answer | |

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.