+ Start a Discussion
yogesh_sharmayogesh_sharma 

Notify "Case Owner" when case comment is created using Apex(Site/Page).

Problem:

I was facing a Issue releted to notify "Case Owner" when case comment is created, even i checked checkbox in our enterprise setting Customize -> Cases -> Support Settings "Notify Case Owner of New Case Comments". Then also my case owner not got notifications.
Below are my code in which i was facing issue:
CaseComment objCaseComment = new CaseComment();
objCaseComment.CommentBody = strComment;
objCaseComment.ParentId = objectCase1.Id;
insert objCaseComment ;
In this code I was simply inserted case comment usnig Apex, but I did some Rnd and got a hint that when we create case comment using Apex(Page/Site) in this scenarion there is a checkbox in EmailHeader "triggerUserEmail" not set to true.

Solutions:

When we create case comment using Apex(Site/Page) we need to set "triggerUserEmail" true. in our existing code.
Even though auto-sent emails can be triggered by actions in the Salesforce user interface, the DMLOptions settings for emailHeader take effect only for DML operations carried out in Apex code.
I added some piece of code in my exisiting code below:
Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerUserEmail = true;
CaseComment objCaseComment = new CaseComment();
objCaseComment.CommentBody = strComment;
objCaseComment.ParentId = objectCase1.Id;
database.insert(objCaseComment, dlo);
Now I get notification when my case comment is created using Apex(Page/Site).
If "Case Owner" and "Case Comment" creator are different then only Case Owner will  get notification else Case Owner will not get notification.
Thanks!
 
sandeep@Salesforcesandeep@Salesforce
Hi,

Thanks for sharing it and I would like to add that in case of sending rich notification you can write a trigger on Casecomment intertion and send email to Case Owner with desired Template. 

Thanks 
Sandeep Singhal
http://www.codespokes.com/
Yogesh Miyani 1Yogesh Miyani 1

Thanks Yogesh Sharma,

Needful information, it's helped me

Rithin JohnRithin John
Hi,

Is there a way to send the standard salesforce mail to case contact also, when a comment is created via Apex?

Thanks 
Rithin John