Ask Search:
Eric CannadyEric Cannady 

add case comments from email

 We have email to case turned on so that customers can reply to emails and they are added to the case but you then end up with two different areas with communication.  comments and email.  This can be very confusing.  So my question is:  Is it possible to automaticly add the body of emails coming and going as case comments.  This way atleast the comment section has all communicaion about a case....

Thanks  
PS we are in the implication process for using salesforce to track cases but we are really struggling with how to communicate with our customers.  They rely on email and the portal to communicate with us and are not going to be really confused not having one section that contains all communication...
Matt BrownMatt Brown
I can understand why you may feel that this would be confusing to your customers but honestly we have over 500 accounts accessing our Customer Portal and not one has been confused by Emails and Comments as forms of communication. Intuitively our Customers will use Comments after the initial Case Submission and Emails responses to communicate with our Support team and visa versa.

However, if you do want to go down the route of turning emails into case comments here would be a solution:

A workflow rule + an apex trigger would work. 
- Make a custom field on Case called "last email."  Don't show it on any page layout.
- Make a workflow rule on Email Message which copies the text of the email to that field.
- Make an Apex trigger on Case which takes that field and makes a new comment out of it.

Both the instructions and the triggers were pulled from these resources:


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;
  }
}

http://community.salesforce.com/sforce/board/message?message.uid=128951
http://community.salesforce.com/sforce/board/message?board.id=general_development&thread.id=17379

This might also be of help:

http://wiki.developerforce.com/index.php/Visualforce_CaseHistoryTimeline




Bruno MalnovicBruno Malnovic
It is a bit of a slippery slope. Many of our customers have no problems with the 2 options to communicate. Others do have some issues, mainly due to the complexity of their own internal organizations.

You could always disable Case Comments, but I wouldn't recommend it. A few minutes spent explaining how the portal works and where customers should look for information usually takes care of the problem.

Also consider that when you create a case comment, you have the potential to generate an e-mail to the customer to notify them of the comment. Using a process to copy an e-mail to a comment could trigger a looping scenario where a case comment generates an e-mail, only to generate a case comment and so on.


Eric CannadyEric Cannady
 Thanks for the ideas.  I guess my main concern is what communication channel to use when.  Case comments seem to be what SF wants you to use as the default but you cannot copy other people and the customer cannot reply to the email they must login to the portal.  If we use email they can reply to the email but if they login to the portal they cannot reply to the email there they have to add a case comment. In turn breaking the communication thread also when you view the emails you only see the first line unless you open it making it much harder to quickly view all the communication you have had with a customer...  Not to mention on consultants want to be copied on case communication which then is going to cause a mass amount of workflow rules to cover all the communication channels creating an admin mess...  Sorry for the rant but I thought moving to SalesForce was going to solve a lot of our problems and it will but their integration of communication channels is lacking... 

Thanks again for the ideas and thoughts.
Eric

Eric CannadyEric Cannady
 I believe I have found the solution we are looking for in the app exchange  "Email to case Premium"
Tim ForehandTim Forehand
Hey Mattybme1,
I'm not sure if you're still checking this thread, I'm trying the suggestion below, but I keep getting the following error when I attempt to save the trigger:
ErrorError: Compile Error: Incorrect SObject type: Case should be EmailMessage at line 1 column 1

ErrorError: Compile Error: Incorrect SObject type: Case should be EmailMessage at line 1 column 1
Error: Compile Error: Incorrect SObject type: Case should be EmailMessage at line 1 column 1

Any idea why I'm getting this?

Thanks,
Tim F
Tim ForehandTim Forehand
Nevermind, I figured out what I was doing wrong.  Now I'm trying to figure out how to move this into production, since the Enterprise edition doesn't give you an easy way to create NEW triggers.
Matt BrownMatt Brown
@tforehand  have you tried using the Deployments? You create a Change Set and place the Apex Trigger in it and then deploy it back to production. That is if you have done this in your Sandbox environment. If you have used a Dev Edition you will need to use the Eclipse IDE to migrate it to your Production org.
Matt BrownMatt Brown
Also I would take a serious look at the Appexchange App called Email-to-Case Premium as it is so much better than the my original solution and it is not very expensive.
Tim ForehandTim Forehand
Hey Mattybme1,
Thanks for the help on this.  I'm still at it though.  I have managed to get the trigger moved into production, but the way it's written, it's creating case comments from the last email every time any of the case fields gets changed, not just when an email is sent.  Do you have any suggestions?  Unfortunately, I don't have the luxury of paying for the email-to-case premium package.

Thanks.
Matt BrownMatt Brown
So an adjustment to where the Apex Trigger needs to reside. It needs to be on Case Comments if you haven't got it there already. Go Setup>App Setup>Customize>Cases>Case Comments>Triggers.

Also the Last Email field needs to be a long text field if it is not already.
Brent TaylorBrent Taylor
Hi There,

I've installed this in to my sandbox org and it works perfectly, when I try and push it into production it give me the test case errors.

Since I'm not a programmer and this is my first and only piece of code I'll need is there any chance a test class was created for this as well?

Thanks!
BT
Adam WallAdam Wall
@tforehand you don't happen to remember what you were doing wrong, do you?  I'm running into the same error.
Steve PaskiSteve Paski
Setup the above steps to get an Email into Comments and it works great, however the "Created By" is taking on the default case owner from Support Settings.  How do I update the "Created By" with the email address of the email sender?  For some reason I cannot locate the correct "From" field to update,  the obvious fields give me an error of not being defined in the Apex code.
Thanks
Steve PaskiSteve Paski
Answered my own question, not possible that I can find.