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
Alex CritchAlex Critch 

How to update last modified date/time when only an activity is added to a case

I have seen some posts with similar issues, but nothing exact to my organization; but apologies in advance if this is a duplicate.

I am trying to figure out how to update the Last Modified Date/Time field when an Activity is added to a case. We do not use email to case, we have our own process in which the support engineer uses the "Log a call" button in the Activity section when information is either sent to the customer or received from the customer.

If that is the only field edited then Last Modified Date/Time is NOT updated. I understand that this is the functionality, but I need to have this field update in order to report on the "Time Since Last Touch" which is a formula I created that compares the Last Modify field with NOW().

I have been told I need an Apex trigger to do this, but as a newbiew to Apex and Salesforce administration tasks I need help. Is this something simple to implement or shoud I just give up?

Any help would be greatly appreciated!
Alex CritchAlex Critch
That doesn't look like my problem... I am not importing anything, just simple adding Activities to a case.
Akhil TandonAkhil Tandon
Hi Alex,

You can use below mentioned code to update case when a task/call log is inserted.
You would have to customize this logic to fit your need.

trigger CaseUpdateonTaskInsert on Task (after insert)
{
    List<Case> lstCase = new List<Case>();
    for(Task T : Trigger.New)
    {
        if(T.WhatId != null && string.valueof(T.WhatId).startsWith('500'))
        {
            Case cs = new Case(id=T.WhatId);
            lstCase.add(cs);
        }
    }
    
    update lstCase;
}

Regards
Akhil Tandon
Alex CritchAlex Critch
Thanks for the code, but it is totally foreign to me, I haven't the slightest clue where to start.