How to download Rich Text Area image from Salesforce to Excel File

In this post, we will talk about how to download rich text images into excel files. Sometimes our clients want to download Contacts or Accounts details into excel files but If records contain any rich text area field which holds images then it might create problems. If you follow the normal procedure then it will not display the image in the excel file. I will share with you how you can achieve this task.

Requirements: Download Rich Text Area image

  • Basic Knowledge of Salesforce public site creation.
  • Knowledge of VisualForce pages and Apex.

Salesforce stores richtext fields images in ContentReference object, but we can not query or see this object from anywhere. If you ever try to print rich text area image field value you will see output like this 

download Rich Text Area image from Salesforce to Excel File

Here eid is a custom object, the “entity ID”. Presumably, you could use this to view an instance of your record and feoid is the “field entity ID”. This describes the field that the content is stored in. You can see this value when you’re looking at the field in the Setup screen and refid is an ID of the type ContentReference


  1. Create a site in salesforce. As we know that our Rich text area data is saved on the RTA server so we can not directly access it or share it publicly so, create a site in salesforce. You can see the sites option in Setup of salesforce.
  2. Allow read access of your Object and Rich Text Field in the Public Access Setting of your site. For example Account object have a rich text area field with name Excel Image, so after allowing it in public access setting it looks like this

    And Field

  3. Create a sharing rule related to your Object and select Shared With Default Help Center Site Guest User
  4. Replace your RTA Image machine URL with your site URL. You must only replace the front portion (till .com) of RTA image with your site link. for ex
    suppose ABC.RichTextImage__c field value is https://cunning-impala-iuaae5-dev-ed–

    And Your Site url is
    so final url must be looks like this
  5. Now you can use this updated URL in apex image tag to render your image in table column for Ex:

VF Page

<apex:page standardController="Account" contentType="application/"  extensions="ExcelController"  >
contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet#MyFile.xls"
contentType="application/; charset=Windows-1151#TESheetDownload.xls"
        width: 100px;
    <apex:outputPanel >
        <table id="aTable" cellpadding="10px" style="width: 100%; border-collapse: collapse;text-align: center; " border="1">
                    <th style="text-align:center;background-color:#e3e5e9" >User Name</th>
                    <th style="text-align:center;background-color:#e3e5e9" >User Logo</th>
                <apex:repeat value="{!lsOfAcc}" var="a"  >
                    <tr >
                        <td > {!}</td>
                         <td  >
                             <apex:image id="theImage" width="65" height="35" url="{!a.logo__c}" />


public class ExcelController {
    public List<Account> lsOfAcc{get;set;}
    public ExcelController(ApexPages.StandardController controller) {
        String name = 'Test%';
        String siteLink ='';        
          lsOfAcc = [Select Id, Name,logo__c from Account Where Name Like :name];
		  for(Account asp : lsOfAcc){
                String temp = (''+asp.logo__c);
                temp = temp.subString(temp.indexOf('"'),temp.indexOf('"', temp.indexOf('"')+1)).replace('amp;','').replace('"','');
                asp.logo__c = siteLink + temp.subString(temp.indexOf('.com')+4,temp.length());	
                System.debug('Temp is '+asp.logo__c);
            }         //

You can see a demo code here 

nischal vasisth

nischal vasisth

Nishchal Vashisht, 2x certified Developer at cloud certitude

Share this article

Leave a reply

Subscribe for Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 3,541 other subscribers

Our Supporter


Apex Hours

Apex Hours is one stop platform to learn Salesforce skills and technology

Join our Newsletter and get tips and tricks how to explore the salesforce for free!