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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 3 down vote accepted

Try: '/servlet/servlet.FileDownload?file='

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

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


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.