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
Sachin Bhalerao 17Sachin Bhalerao 17 

Error on save button on inline editing

When m click on save button m getting error . Data is getting update . But this error messgae appearing

Error on save button
Best Answer chosen by Sachin Bhalerao 17
Khan AnasKhan Anas (Salesforce Developers) 
Hi Sachin,

Greetings to you!

I request you please post the complete code snippet of what you have tried so that we can look into it and can help you accordingly.

Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement. Please note that lightning is case sensitive. 

Apex:
public class UpdateDataTable_TaskSvrController {
    
    @AuraEnabled
    public static List<Account> details(){
        List<Account> lst = [SELECT Name, Phone, Rating, NumberOfEmployees FROM Account LIMIT 10];
        return lst;
    }

    @AuraEnabled
    public static List<Account> updateDetails(List<Account> lstForm) {
        update lstForm;
        return lstForm;
    }
}

Component:
<aura:component controller="UpdateDataTable_TaskSvrController"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="PageHeading" type="String" default="Update Using Data Table"/>
    <aura:attribute name="mydata" type="Account"/>
    <aura:attribute name="mycolumns" type="List"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:handler event="force:refreshView" action="{!c.doInit}" />
    
    <lightning:datatable aura:id="iliDataTable"
                         data="{! v.mydata }"  
                         columns="{! v.mycolumns }" 
                         keyField="Id" 
                         hideCheckboxColumn="false" 
                         onsave="{!c.saveTable}" />
</aura:component>

Controller:
({
    doInit : function(component, event, helper) {
        component.set('v.mycolumns', [
            {label: 'Account Name', fieldName: 'Name', type: 'text', editable: true, initialWidth: 750},
            {label: 'Phone', fieldName: 'Phone', type: 'phone', editable: true},
            {label: 'Rating', fieldName: 'Rating', type: 'text', editable: true},
            {label: 'Number Of Employees', fieldName: 'NumberOfEmployees', type: 'number', editable: true}
        ]);
        
        var action = component.get("c.details");
        action.setCallback(this, function(response) {
            var state = response.getState();
            
            if (state === "SUCCESS") {
                var res = response.getReturnValue();
                component.set("v.mydata", res);
            }
            else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + 
                                 errors[0].message);
                    }
                } 
                else {
                    console.log(response.getReturnValue());
                }
            }
        });
        $A.enqueueAction(action);
    },
    
    saveTable : function(component, event, helper){     
        //var data = component.get("v.mydata");
        var draftValues = event.getParam('draftValues');
        var action = component.get("c.updateDetails");
        action.setParams({lstForm  : draftValues});
        action.setCallback(this, function(response) {
            var state = response.getState();
            
            if (state === "SUCCESS") {
                var res = response.getReturnValue();
                $A.get('e.force:refreshView').fire();
                alert('Updated Successfully...');
            }
            else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + 
                                    errors[0].message);
                    }
                } 
                else {
                    console.log(response.getReturnValue());
                }
            }
        });
        $A.enqueueAction(action);
    }
})

Application:
<aura:application extends="force:slds">
    <c:UpdateDataTable_Task />
</aura:application>

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Sachin,

Greetings to you!

I request you please post the complete code snippet of what you have tried so that we can look into it and can help you accordingly.

Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement. Please note that lightning is case sensitive. 

Apex:
public class UpdateDataTable_TaskSvrController {
    
    @AuraEnabled
    public static List<Account> details(){
        List<Account> lst = [SELECT Name, Phone, Rating, NumberOfEmployees FROM Account LIMIT 10];
        return lst;
    }

    @AuraEnabled
    public static List<Account> updateDetails(List<Account> lstForm) {
        update lstForm;
        return lstForm;
    }
}

Component:
<aura:component controller="UpdateDataTable_TaskSvrController"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="PageHeading" type="String" default="Update Using Data Table"/>
    <aura:attribute name="mydata" type="Account"/>
    <aura:attribute name="mycolumns" type="List"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:handler event="force:refreshView" action="{!c.doInit}" />
    
    <lightning:datatable aura:id="iliDataTable"
                         data="{! v.mydata }"  
                         columns="{! v.mycolumns }" 
                         keyField="Id" 
                         hideCheckboxColumn="false" 
                         onsave="{!c.saveTable}" />
</aura:component>

Controller:
({
    doInit : function(component, event, helper) {
        component.set('v.mycolumns', [
            {label: 'Account Name', fieldName: 'Name', type: 'text', editable: true, initialWidth: 750},
            {label: 'Phone', fieldName: 'Phone', type: 'phone', editable: true},
            {label: 'Rating', fieldName: 'Rating', type: 'text', editable: true},
            {label: 'Number Of Employees', fieldName: 'NumberOfEmployees', type: 'number', editable: true}
        ]);
        
        var action = component.get("c.details");
        action.setCallback(this, function(response) {
            var state = response.getState();
            
            if (state === "SUCCESS") {
                var res = response.getReturnValue();
                component.set("v.mydata", res);
            }
            else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + 
                                 errors[0].message);
                    }
                } 
                else {
                    console.log(response.getReturnValue());
                }
            }
        });
        $A.enqueueAction(action);
    },
    
    saveTable : function(component, event, helper){     
        //var data = component.get("v.mydata");
        var draftValues = event.getParam('draftValues');
        var action = component.get("c.updateDetails");
        action.setParams({lstForm  : draftValues});
        action.setCallback(this, function(response) {
            var state = response.getState();
            
            if (state === "SUCCESS") {
                var res = response.getReturnValue();
                $A.get('e.force:refreshView').fire();
                alert('Updated Successfully...');
            }
            else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + 
                                    errors[0].message);
                    }
                } 
                else {
                    console.log(response.getReturnValue());
                }
            }
        });
        $A.enqueueAction(action);
    }
})

Application:
<aura:application extends="force:slds">
    <c:UpdateDataTable_Task />
</aura:application>

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Sachin Bhalerao 17Sachin Bhalerao 17
Dear Khan Anas ,

Now it is working . Thank you for your support .

Thanks & Regards
Sachin Bhalerao