function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Suman MSuman M 

How to the Source URL of an Image inserted in RichTextArea into Apex

Hi,

We have rich text area field on an Object, This field is used to show its content on a VisualForce page on a Community. When we Insert images into this field we are not able to see the Image on the VF page on the community. Below is the error.
User-added image
When I see the source of the Page, using Inspect Element.  the SRC URL is something like this .
<img alt="User-added image" src="/servlet/rtaImage?eid=a1SO0000001mlcp&amp;feoid=00N90000009jGOn&amp;refid=0EMO000000005er"></img>

But, here when I upload a Image into Documents in salesforce and Add an Image in this field using the Image URL, I'm able to see the Image on the Community Page. Then the SRC URL is looking like this.
src="https://org--qa--c.cs5.content.force.com/servlet/servlet.ImageServer?id=015O0000000MH0Q&amp;oid=00DO0000000VdkF&amp;lastMod=1415956267000">.

Is there anyway we can get this URL through Apex an using in the VF Page. Below is part of Apex.

 public List<NewsItem> getOutages() {
        return convertSObjectCustomNewsItemList(messages.get(PLANNED_OUTAGE));
    }

    public List<NewsItem> getFeatures() {
        return convertSObjectCustomNewsItemList(messages.get(NEW_FEATURE));
    }

    public List<NewsItem> getEvents() {
        return convertSObjectCustomNewsItemList(messages.get(MAJOR_EVENT));
    }

    /*
    Helper method to convert a 'native' list of MyWSE_News__c to a list of the public inner NewsItem 
    class. Done so we can hide the MyWSE_News__c object from relevant profiles and use the data in 
    custom VF pages
    */
    private List<NewsItem> convertSObjectCustomNewsItemList(List<MyWSE_News__c> mywseNewsEvents) 
    {
        List<NewsItem> returnList = new List<NewsItem>();
        system.debug('mywseNewsEvents>>'+mywseNewsEvents);
        if(mywseNewsEvents != null) 
        {
            for(MyWSE_News__c event : mywseNewsEvents) 
            {
                NewsItem newsItem = new NewsItem();
                newsItem.name = event.name;
                newsItem.description = event.description__c;
                newsItem.createdDate = event.createddate.format();

                returnList.add(newsItem);
            }
        }

        return returnList;
    }

    public class NewsItem {
        public String name {get; set;}
        public String description {get; set;}
        public String createdDate {get; set;}

        public NewsItem() {
            name = '';
            description = '';
            createdDate = '';
        }
    }
}
ShashankShashank (Salesforce Developers) 
You should definitely be able to use the document URL in a VF page without the need of uploading it in a field in a custom object.