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?

| improve this question | | | | |

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

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.

| 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.