I am trying to update the value of a field inside of a list to be returned to the LWC component. I don't want the update to happen on the database, but just on the UI.
As datetime values are stored in GMT, I am converting it to the users local timezone value just to be displayed in the UI.
With the below code I am getting this error - Field is not writeable - points to the CreatedDate field.
public with sharing class theController {
@AuraEnabled
public static List<Task> getAllRecords(String contactRecordId) {
TimeZone tz = UserInfo.getTimeZone();
DateTime yesterday = System.now() - 1;
List<Task> allTasks = [SELECT ID, CreatedDate FROM Task Where contact = :contactRecordId AND CreatedDate >= :yesterday];
for(Task theTask: allTasks) {
Datetime createdDate = theTask.CreatedDate.AddSeconds(tz.getOffset(theTask.CreatedDate)/1000);
theTask.CreatedDate = createdDate;
}
return allTasks;
}
}
Please advise. Thank you all.
UPDATE as per identigral reference to the post with same issue
TimeZone tz = UserInfo.getTimeZone();
for(Task theTask: allTasks) {
Datetime createdDate = theTask.CreatedDate.format('yyyy-MM-dd hh:mm', tz);
theTask.CreatedDate = createdDate;
}
What could be wrong above , I get an error saying method does not exist or incorrect signature for the format method.