+ Start a Discussion
zameer katwalzameer katwal 

How to upload image from my local system to custom object field which is a Rich Text Area

<apex:page showHeader="false" sidebar="False" controller="InsertOEMIncentive" docType="html-5.0">
<apex:form >
    IncentiveType_Name<apex:inputText value="{!IncentiveType_Name}"/><br/>
   IncentiveType_Description<apex:inputText value="{!IncentiveType_Description}"/><br/>    
  IncentiveType_Image<apex:inputFile value="{!IncentiveType_Image}"/><br/>
  Incentive_EndDate<apex:input type="date" value="{!Incentive_Type_EndDate}"/><br/> 
   Incentive_StartDate<apex:input type="date" value="{!Incentive_Type_StartDate}"/><br/> 
    <apex:commandButton value="save" action="{!saveList}"/>
Sfdc CloudSfdc Cloud
Hi Zameer,

You can acheive this requirement using formula field.What you need to do is u have to store image file in attachment.After that you need to store this image url in custom field which will be hidden from pagelayout.For that you will  create two custom field.

1.Custom field Name "StoreImageUrl" which will store image url.
2.Custom field of formula type with Name "Image" which will show ur image on object.(Type:text/Rich Text Area).y 

Try below code it is working fine in my org.

Visualforce Page
<apex:page standardController="contact" sidebar="false" extensions="myAccount"> 
<apex:form >
                <apex:outputpanel layout="block">
                    <apex:pageblock mode="maindetail" >           
                        <apex:pageblocksection columns="1" >                
                              <apex:inputFile value="{!photo}"> </apex:inputFile> 
                              <apex:commandButton value="Upload photo" action="{!uploadphoto}" /> 
Apex Classes
public with sharing class mycontact{

    private  contact con;;
    public blob Photo{get;set;}
    public String Con {get;set;}

    public mycontact(apexpages.standardController controller)
    public void UploadPhoto(){
           Con= ApexPages.currentPage().getParameters().get('id');  
           // inserting attachement with Attached photo      
            Attachment objA=new Attachment();
            objA.body = photo;
            objA.name = 'testname';
            objA.parentid= con.id;
            objA.ContentType = 'application/jpg';
            insert objA;
            string Attid= objA.id;
            string attachmentid=Attid.substring(0,15);
            con.StoreimageUrl__c = '/servlet/servlet.FileDownload?file='+attachmentid;
            Update con;
        }catch(Exception e){
            system.debug('Exception message'+e);
 Formula Field (Image)
IF( StoreImageUrl__c != null , IMAGE( StoreImageUrl__c , '' , 100 , 100 ) , IMAGE('' , '' , 0 , 0));

If this will helps out.Mark it best answer to help others 
Thanks :)