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
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}"/>
</apex:form>
</apex:page>
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:pageblocksection>
                    </apex:pageblock>
                 </apex:outputpanel>
 </apex:form>
</apex:page>
Apex Classes
public with sharing class mycontact{

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

    //Contstructor 
    public mycontact(apexpages.standardController controller)
    {
    }
    
    public void UploadPhoto(){
        try{
         
           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 :)