Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have a query fetching a document which is an image. I want to assign the image to a field (URL).

I am doing:

Document doc = [select id, name,url, body from Document where name = 'image'];
Object.URLFIELD__c = doc.url;

However the image is always broken. I set it available for external use.

Is there a good way to reference the image in visualforce?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Try: '/servlet/servlet.FileDownload?file='+doc.id

Description
This article will help to show an image into the visual force page from the attachment object or document.

Resolution
The image can be displayed in the VF page by using tag. Image source is specified by "URL" attribute. But the url should be in the form : " /servlet/servlet.FileDownload?file=xxxxxxxxxxx" where xxxxxxxxxxx is the the unique id of theDocument/Attachment record containing the image.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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