+ Start a Discussion
Jeremy Thomas 15Jeremy Thomas 15 

Error when saving lightning-datatable edit on Time field

I'm creating a custom lightning-datatable component. As part of it I can edit a field of type "Time". When I do though and click save, I get the following error: "alue for field 'Start_Time__c' is not in ISO 8601 format, Value: 1970-01-01T15:00:00.000Z, Runtime class: java.lang.String"

My save handler looks like this:

const fields = {};
         fields[ID_FIELD.fieldApiName] = event.detail.draftValues[0].Id;
         fields[START_TIME.fieldApiName] = event.detail.draftValues[0].Start_Time__c;

         const recordInput = {fields};
          updateRecord(recordInput).then(() => {
                new ShowToastEvent({
                    title: 'Success',
                    message: 'Contact updated',
                    variant: 'success'

            // Display fresh data in the datatable
            return refreshApex(this.agendaItems).then(() => {
                // Clear all draft values in the datatable
                this.draftValues = [];
          }).catch(error => {
                new ShowToastEvent({
                    title: 'Error updating or reloading record',
                    message: error.body.message,
                    variant: 'error'
This seems like it should be so simple, but I can't get it to work.

What should I be doing to the value I get from event.detail.draftValues[0].<Time field that was updated> when adding it to the list of fields to update?
Suraj Tripathi 47Suraj Tripathi 47

Hi Jeremy Thomas 15,

I Think you have to use date.format() method so that it will format datetime in string format so that you can easly add it to field.


fields[ID_FIELD.fieldApiName] = event.detail.draftValues[0].Id;
DateTime dt = event.detail.draftValues[0].Start_Time__c;
fields[START_TIME.fieldApiName] = dt.format();

if you find your Solution then give it as BEST ANSWER .


Suraj tripathi