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

  • PRANAV

    Member
    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

    Member
    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.

    1222

  • PRANAV

    Member
    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();

    d.name = 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="https://pranavbhardwaj-dev-ed--c.ap6.content.force.com/servlet/servlet.FileDownload?file='+d.id+'" width="500" height="281"></img>'; //FirstExample is namespace & image_field__c is Rich Text Area field
    cs.Status = 'New';
    cs.Origin = 'Web';
    insert cs;
    }
    }

  • PRANAV

    Member
    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"/>
    </apex:form>
    </apex:page>

    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

    imagecase

    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.

    Thanks

  • Harsh

    Member
    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.

     

     

     

  • PRANAV

    Member
    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

    success.salesforce.com/ideaView?id=08730000000sZ4VAAU

    success.salesforce.com/ideaView?id=0873A000000CL9mQAG

     

  • shariq

    Member
    September 20, 2018 at 6:52 pm

    Hi,

    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

    Member
    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.

     

    Thanks

Log In to reply.

Popular Salesforce Blogs