Activity Forums Salesforce® Discussions How can i add the ability to upload image using richtext in inputTextArea?


    April 18, 2018 at 10:57 am

    Hi Harsh,

    Yes you can achieve this through your VF Page button "Choose File".

    You just have to write your Apex controller to insert a Document for "Choose File" and in your apex code you can add that document record id to the sobject where you want to use this inputTextArea richtext / attached file.

    Hope this helps you. If you want I can help you with the code also.


  • Harsh

    April 18, 2018 at 11:10 am

    Please help me with the code as i am new in the coding and please do it earliest as it is P1 priority ticket.

    Please make it sure my required is like below snapshot, were i wanted to upload my image in the richtextarea only.



    April 18, 2018 at 11:42 am

    Hi Harsh,

    The below code will help you for this.

    // Apex Class

    public class InsertImageIntoRichText

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

    public void insrt()

    Document d= new Document(); = fname;
    d.body=file; // body field in document object which holds the file.
    d.folderid='00l0K000001GJlF'; //folderid where the document will be stored insert document;
    insert d;

    Case cs = new Case();
    cs.pack_age_test__image_field__c = '<img src="''" width="500" height="281"></img>'; //FirstExample is namespace & image_field__c is Rich Text Area field
    cs.Status = 'New';
    cs.Origin = 'Web';
    insert cs;


    April 18, 2018 at 11:53 am

    Here's the VF Page Code

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

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

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

    Now when you add image through this VF page, the image is inserted and attached to a Rich Text Area custom field on Case. Like


    Hope you will get your solution now. It's a much similar code of what you needed if you want something more/different you can play around the Code and built your required functionality.


  • Harsh

    April 18, 2018 at 12:51 pm

    Hi Pranav,

    Thanks for the code, but can u please implement the same in event object as i am getting it some error when i tried to implement this code in my org.





    April 18, 2018 at 2:32 pm

    Hi Harsh,

    For now Rich Text field is not available for Event Object.

    Here's some ideas on Salesforce IdeaExchange for adding Rich Text field on Activities object


  • shariq

    September 20, 2018 at 6:52 pm


    This what I found online -

    About Rich Text Editor
    At a high-level, the buttons in RTE are organized into four groupings: “format text”, “format body”, “insert content”, and “clear formatting”.

    The “clear formatting” button always stays at the end of the buttons set, regardless of which rich text editor variant is used. It should always stand by itself.

    On smaller screen sizes, the select dropdowns for Font and Size in the toolbar can overlap outside of the container. To adjust the widths of the dropdowns, apply the class slds-region_narrow to the outermost div of the rich text editor.

    A label may be used to further describe the purpose of a Rich Text Editor. To add a label, place a <span> element with the class slds-form-element__label, right before the slds-form-element__control element.

    Hope this helps.

  • Parul

    September 20, 2018 at 7:05 pm

    Adding some points:

    WARNING If you add a custom rich text area field in Salesforce Classic and edit it in Lightning Experience, you can also expect the formatting differences. Saving your changes in Lightning Experience overwrites the original formatting you had in Salesforce Classic and conversely. Alternatively, you can fix some of the formatting using the toolbar or switch to Salesforce Classic to perform your edits.



Log In to reply.

Popular Salesforce Blogs