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
Ido Greenbaum 10Ido Greenbaum 10 

Case Trigger to replicate case.description to a Rich Text field - images appear as 'inline image'

I have the following Trigger on case, to copy the HTMLBody of the first Incoming EmailMessage (for 'Email' originated cases), into a custom Rich-Text field:
 
trigger updateCaseDescription on Case (before update) {
    set<Id> parentIds = new set<Id>();
    map<Id,EmailMessage> mapEmailMessage = new map<Id,EmailMessage>();
    for(Case c:trigger.new){   
        parentIds.add(c.Id);
    }   
    list<EmailMessage> lste = [select id,HtmlBody,parentId from EmailMessage where parentid in:parentIds and Incoming = true ORDER By parentId];

    if(lste.size() > 0 ){
     for(EmailMessage e:lste){
    if(!mapEmailMessage.containsKey(e.parentId))
    {
       mapEmailMessage.put(e.parentId,e);
    }
}
     list<Case> lstC = new list<Case>();
     for(Case c:trigger.new){ 
      if
      (mapEmailMessage != null && mapEmailMessage.get(c.Id) != null && String.isBlank(c.Description_HTML__c) && c.Origin == 'Email')  
          c.Description_HTML__c = mapEmailMessage.get(c.Id).HtmlBody;       
     }
    }
}

The trigger is working properly, but I can't seem to find how to present the Images (instead of 'inline image'):
User-added image
LBKLBK
When you copy the HTML Body, you need check where those images are referred from.

Unless the images are stored in a place and can be referred back to, images cannot be rendered in HTML.

In my understanding, the email content (along with the inline images) are stored in the data storage and not in the file storage.

these images can be referred in your content, only if they are stored in the file storage.