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

Help with CaseComment Trigger ?!?

I have a requirement to code an Apex Trigger that fires with a CaseComment changes and SalesForce Premier Support says this is possible once I learn the tricks so I am here asking about those tricks.


Thanks in advance for the help.

Venkat PolisettVenkat Polisett

Please be specific about your question. If possible post some code.


What are you planning on doing in your trigger?


Explain, then we can help you. May be there a better way than a trigger.


There is no CaseComment trigger, but here is how to figure out if a Case Comment caused a Case trigger to fire without using workflow...The LastModifiedDate field of both the Case and CaseComment records are updated when a Case Comment is modified. However, when a Case record is modified, the LastModifiedDate of any associated CaseComment records are not modified. Consequently, you can compare the LastModifiedDate of the CaseComment records against the LastModifiedDate of the parent Case that generated the trigger. If the LastModifiedDate of the Case record is newer than that of the child CaseComment, changes to the Case record caused the trigger. Otherwise, changes to the CaseComment caused the trigger.


Here is the simulated CaseComment Trigger code 


// The trigger
trigger AfterUpdateCaseComment on Case (after update) {
   for (Case C : {

// The class invoked by the trigger
public class CaseCommentsHandler{
   public static void handleCaseComments( Case C ){
      Case aCase = [SELECT LastModifiedDate FROM Case WHERE Id = :C.Id];
         CaseComment aCaseComment = [SELECT LastModifiedDate FROM CaseComment

WHERE ParentId = :C.Id ORDER BY LastModifiedDate DESC LIMIT 1];
         if (aCaseComment.LastModifiedDate >= aCase.LastModifiedDate){
            // Put your code to handle a simulated CaseComment Trigger here
            System.debug('Yahtzee! CaseComment Trigger');
      } catch (Exception e){
         System.debug('This Case has no Case Comments.. ');


Message Edited by stang on 04-28-2009 03:40 PM

Hi there,


I have tested the above and found that the when a new comment is added  the 'LastModifiedDate' in Case is not updating according to the timestamp of the new comment.

Actually, it is not updating at all.


I tested in both application and via debug logs (the case triggger isn't fired).


Did I miss anything?