0

I create a text(rich) field for an Object and put an image on this field. But when I want to show it on the page I wrote by VisualForce, the image turns to be a URL like this:

<img src="http://www.gdhtcm.com/uploadfiles/20170314103122705.png"></img>

How to show the image besides using Static Resource?

1
  • use <img src={!your_link}/>?
    – Novarg
    Commented Mar 20, 2017 at 10:14

2 Answers 2

2

In RichText Field the Image is stored as below. You have to use String operation to get the Image URL.

enter image description here

Book__c book = [SELECT Id, Rich_Text__c FROM Book__c LIMIT 1];
String imgTag = book.Rich_Text__c.substringBetween('<img', 'img>');
String imgUrl = imgTag.substringBetween('src="', '"');
String imgUrlFinal = imgUrl.replace('amp;', '');         
System.debug('imgUrlFinal : ' + imgUrlFinal);

Use this imgUrl in VisualForce page to show the image.

<img src="{!imgUrl}"/>
2
  • Thanks!But do you know why the image URL I get will include a string 'amp;' and I have to delete it to get the correct image URL? Commented Mar 21, 2017 at 10:04
  • You can remove the amp; by replace function of the String class.
    – Saroj Bera
    Commented Mar 21, 2017 at 12:59
1

you can bind with Resource for fetching image from static resouce

<apex:image url="{!$Resource.**put your resource name here!!**}"/>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .