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
Arjun y 7Arjun y 7 

Unable to insert rich text area image in documents

Hi All,

I need to insert a rich text area field's image in documents/attachments in a custom object.

Can anyone guide me how to insert a rich text area image record in custom object?

Thanks
Arjun
Andrew LokotoshAndrew Lokotosh
Hi Arjun. 

You can use that code 
public class ImagInsertionIntoRichText
{

 public String naam{get;set;}
 public ID folderid{get;set;}
 public Blob file{get;set;}

 public void insrt()
 {

 Document d= new Document();

 d.name = naam;
 d.body=file; // body field in document object which holds the file.
 d.folderid='00l90000000inFEAAY'; //folderid where the document will be stored insert d;
 insert d;

 Case cs = new Case();
 cs.FirstExample__Comments__c = '<img src="https://rustagiankit-developer-edition--c.ap1.content.force.com/servlet/servlet.FileDownload?file='+d.id+'" width="500" height="281"></img>'; //FirstExample is namespace & Comments__c is Rich Text Area field
 cs.Status = 'New';
 cs.Origin = 'Web';
 insert cs;
 }
}
*************************************
***************VF page***************

<apex:page controller="ImagInsertionIntoRichText">
 <apex:form>
  <apex:outputLabel value="Document Name"></apex:outputLabel>
  <apex:inputText id="name" value="{!naam}"/>

  <apex:outputLabel value="Upload Document"></apex:outputLabel>
  <apex:inputfile value="{!file}"></apex:inputfile>

  <apex:commandButton value="Save" action="{!insrt}" id="save"/>
 </apex:form>
</apex:page>

Source: http://ankit-rustagi.blogspot.com/2012/10/to-insert-image-into-rich-text-area.html

If you have question fill free to ask.

Please Mark my post as best answer if that helps you!
Thanks!