Wednesday, September 24, 2014

How to display an Image in richtext area field when Image is in attachments

Ok so now if I want to display the same image that is in the attachment of a record? Confused I know as images are stored by salesforce in the back end are not available by simple URL access an Eg:


<img alt="User-added image" height="281" src="https://c.ap2.content.force.com/servlet/rtaImage?eid=00390000018kf3r&amp;feoid=00N9000000XXXX&amp;refid=0EM9000000XXX" width="500"></img>
This is how salesforce saves the image in the rich text box and now if we need to save any kind of image we can, as we just need the 18 digit Id of the saved image.

An attachment has a 18 digit Id and we can use this as Eg:


<img src="https://c.ap2.content.force.com/servlet/servlet.FileDownload?file=00P9000000DXXXX" width="500" height="300"></img>
Wola!! now we can save any image to richtext area form apex code or by query editor. give it a try and ask me if you have any questions.

Hope this helps!!

Note: Refer - http://ankit-rustagi.blogspot.in/2012/10/to-insert-image-into-rich-text-area.html

No comments:

Post a Comment