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
KIBLKIBL 

Last Case Comments

I need to run a report that shows me only the Last Case Comment on a Case.  I added a field to the Case called Last Case Comments.  I created a workflow to update this field with the body of the case comment (every time a record is created or edited).  It works but then I deleated the Case Comment but the report still shows them.  Also,  if you edit a previous comment, it will update the field as well.  I only want this field to be populated with the very last Case Comment on the Case.  I also do not want them to show on the report if they are deleted.

 

Any ideas?

werewolfwerewolf

Workflow does not get run on delete.  If you want it to truly show the last case comment then you'll have to make an Apex trigger on case comments to handle insert, update and delete.

 

If you just want the last comment field to be filled when a comment is created, then set the workflow rule such that it only fires when the object is created (as opposed to when it's created or edited).  That's a setting at the workflow rule level.

NBlasgenNBlasgen

As warewolf says, a trigger is best.  So you're going to need two.  Last Case Comment and Previous to Last Case Comment (2nd to last comment).

 

A) Upon creation: Copy last comment into 2nd to last comment. Set Last Case Comment to Body of created Comment.

B) Upon update: If the original text is equal to either the last comment or 2nd to last comment, update that field.

C) Upon delete: If the deleted comment equals last comment, copy the contents of 2nd to last comment into last comment and blank out 2nd to last comment.

 

Code should work fine unless the last two comments get deleted since we don't keep track of the 3rd.

 

scamarascamara

Hi,

 

I stumbled upon this thread and was wondering if you could actually explain how you got the Field Update for the Last Case Comment to show up as a Existing Action for the Workflow Rule itself.  I'm trying to do exactly what you did (not using Apex).  I think it's not showing up because the Workflow is for Case and Field Update is for Case Comments.

 

Any help or insight would be greatly appreciated.

 

Thanks,

Sergio

 

 

 

scamarascamara

Actually, nevermind.

 

After posting to the thread, I actually realized what I was doing wrong. haha   I'm all set.