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
prbprb 

Email to Case - Store as case comment

Does anyone have a best-practices recommendation for adding a case email as a case comment?

It seems odd to me that when you activate email to case the messages are stored as emails and not case comments.  My first instinct is to make an s-control to merge these two into one display but it seems that I'm missing something simple.  I can't be the first person to encounter this.  How are other people handling this?

 

 

Best Answer chosen by Admin (Salesforce Developers) 
prbprb

I created an s-control that merged emails and case comments into one display to avoid needlessly duplicating content.

 

 

All Answers

werewolfwerewolf

Emails and case comments are logically separate things -- email messages contain much more info.  You could make a workflow from email messages that copies the contents of the body of the email to a field on Case, and then make a trigger on Case which makes a comment out of that field.

 

Or perhaps you could modify the Visualforce Case History Timeline to your needs.

prbprb

I created an s-control that merged emails and case comments into one display to avoid needlessly duplicating content.

 

 

This was selected as the best answer
tapinetapine

That is a great idea, and it works for me. Mostly. Unfortunately I cannot figure out how to clean up the this field's text afterwards.

 

Here's my simple trigger:

trigger commentMove on Case (after update) {
Case myCase = trigger.new[0];
if (myCase.Last_email__c!= null) {
String caseId= myCase.ID;
CaseComment cc = new CaseComment(CommentBody=myCase.Last_email__c,parentID=caseId);
insert cc;
}
}

 

You cannot do

 

myCase.Last_email__c = null;   

 

in the trigger, as you cannot modify Case object on "after update". You cannot use "before update" because then you cannot insert comments. 

 

It's my APEX first trigger, so I apologize if it's a dumb question - but any help will be greatly appreciated.

BT28BT28

Hi There,

 

Thanks for the code snippet I'm trying to use this in my production org but it's giving me an error that I don't have enough Test Coverage.

 

This is my first and only apex trigger I'll need is there any chance you can help with the test class?

 

Thanks!

BT