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
Shivangi Singh 57Shivangi Singh 57 

Date/Time Field should not update on updating Case Status

I have a situation when Case Status field can be updated multiple times but what I need is once I made the status as closed, Date/Time closed field (under case object) should capture the 1st date time stamp when the case was closed and it should NOT be updated again irrespective of how many time status is getting changed.
Please help. Thanks in advance :)
Sukanya BanekarSukanya Banekar
HI Shivangi,

When updating the Closed Date/Time field, ensure to add filter criteria to perform the update only when the field is NULL or blank.

Hope this helps you to resolve the issue.

Sukanya Banekar
Naresh Kaneriya 9Naresh Kaneriya 9

HI @Shivangi Singh,

You can create an Apex trigger on the Case object that fires before update.
In the trigger, check if the Case Status is changing to "Closed" and if the Date/Time Closed field is already populated. 

If the conditions are met, prevent the update and display an error message indicating that the Date/Time Closed field should not be updated once set.

Here's a high-level example of how the trigger might look:

trigger PreventDateTimeUpdate on Case (before update) {
    for (Case caseRecord : {
        Case oldCaseRecord = Trigger.oldMap.get(caseRecord.Id);
        if (caseRecord.Status == 'Closed' && oldCaseRecord.Status != 'Closed' && caseRecord.DateTimeClosed__c != null) {
            caseRecord.DateTimeClosed__c.addError('Date/Time Closed cannot be updated once set.');

Remember to replace DateTimeClosed__c with the actual API name of your Date/Time Closed field.

By using this approach, you ensure that the Date/Time Closed field is only updated when the status changes to "Closed" and only if it's not already set. If the field is set and the status is changed again, the trigger will prevent any further updates and display an error message.

If you believe that this solution will address your issue, kindly consider marking this response as the best answer.