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

Tuesday, September 23, 2014

How to display a image if you have Bas64 sting on a visualforcfe page

Ok so recently I got a requirement that the image is saved in a Base64 format and when it is displayed it should be displayed as image.

What? Right and here is a small trick to do the job.

<img alt="<image_Name>" src="data:image/<image_File_Extension>;base64, <base64_Image_String>"></img>
http://developer.force.com/cookbook/recipe/converting-a-rich-text-area-fields-image-for-api-upload

Hope this helps!!