Activity › Forums › Salesforce® Discussions › How can i add the ability to upload image using richtext in inputTextArea?
-
How can i add the ability to upload image using richtext in inputTextArea?
Posted by Harsh on April 18, 2018 at 9:05 AMParul replied 7 years, 7 months ago 4 Members · 8 Replies -
8 Replies
-
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.
- [adinserter block='9']
-
-
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;
}
} -
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
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
-
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.
-
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
-
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.
-
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.


