Handling Inline Images of the Email Content from Email-to-Case

A field in Case object should capture the inline images, when a new Case is created via Email-to-Case. Most of us will store the htmlbody field of the Email message to a custom case field by writing a Trigger for Email Message.


A field in Case object should capture the inline images, when a new Case is created via Email-to-Case. Most of us will store the htmlbody field of the Email message to a custom case field by writing a Trigger for Email Message.

Existing Solution: 

By enabling HTML email checkbox in Email-to-Case settings, we can get the HTML content of the email in Emails related list of the Case.

HTML contents like tables are added directly to the Email Message object of the Case, but the images are added as attachments to the Emails.

Below is the sample code Written in Email Message: 

trigger HandlingHtmlContent on EmailMessage
(after insert) { List<Case> caselist =
new List<Case>();  
   for(EmailMessage em : Trigger.New){ 

Case curCase = new Case(); 

curCase.Id = em.parentId; 

curCase.emailContent__c = em.HtmlBody(); 



update caseList ;    

Email content: 

inline image email

The value stored in Salesforce:  

inline image email

None of the existing methods can handle your email’s inline images. I searched communities a lot and realized that many people had the same issue but they never found any solution.

Please refer the link https://success.salesforce.com/ideaview?id=08730000000Gp9dAAC

New Solution: 

We face this challenge only for the images. I found that the images are not loaded in single transaction. So, I updated the code by using @future. We have to modify the existing trigger as shown below.

public class getHtmlHandler{ 
static list<case> caseList = 
new list<case>(); 
public static void processEmailMessage
(List<Id> emailMsgIds){   
    for(EmailMessage em :
[SELECT Id, ParentId, HtmlBody FROM 
emailMessage WHERE Id IN: emailMsgIds]){ 
       case cc = new case(); 
       cc.id = em.ParentId; 
       cc.emailContent__c = em.HtmlBody; 
   update caseList ; 

trigger HandlingHtmlContent on
EmailMessage (after insert) { 
List<Id> emailMsgId = new List<Id>();  
   for(EmailMessage em : Trigger.New){ 

Now the value stored in Salesforce: 

how to embed image in email


We can capture all inline html contents of the email sent via Email-to-Case by using the above Apex code with @future annotation.

About MST

At MST Solutions our cornerstone is to adapt, engage and create solutions which guarantee the success of our clients. The talent of our team and experiences in varied business verticals gives us an advantage over other competitors.

Recent Articles

Work with us.

Our people aren’t just employees, they are key to the success of our business. We recognize the strengths of each individual and allow them time and resources to further develop those skills, crafting a culture of leaders who are passionate about where they are going within our organization.