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
jishan royjishan roy 

i want this trigger in case object where any latest comment add on comment then it will show in the case field which is latest comment field

please help me out it is urgent.
Rohit Kumar SainiRohit Kumar Saini
Hello,

As the DML is happening on CaseComment object ( you are inserting a new CaseComment), we need a trigger on CaseComment object. It can be as simple as below ( assuming you don't have any other trigger on CaseComment).
 
trigger CaseCommentTrigger on CaseComment (after insert) {
    List<Case> casesToUpdate = new List<Case>();
    for(CaseComment cc: Trigger.New){
        Case caseToUpdate = new Case(Id=cc.ParentId, Latest_Comment__c=cc.CommentBody);
        casesToUpdate.add(caseToUpdate);
    }
    update casesToUpdate;
}
Please try it and let me know how it goes. Thanks!