0

Component

<aura:component controller="CaseEdit">

    <aura:attribute name ="data" type="Object"/>
    <aura:attribute name ="columns" type="Object"/>
    <aura:attribute name= "caseEdit" type= "Object" /> 
    <aura:attribute name="valueInput" type="String" />

    <div classes="slds-page-header">
        <div class="slds-align_absolute-center" style="height:5rem">Case Detail</div></div>
    <form class="slds-form--stacked">
        <div class="slds-p-around_small">

            <lightning:input aura:id="CasesForm" label="Users ID"
                             name="caseToSearch"
                             value= "{!v.valueInput}"
                             required="true"/>

            <lightning:button label="Get Case Log"
                              class="slds-m-top--medium"
                              variant="brand"
                              onclick="{!c.submitID}"/>

        </div>
    </form>

    <div class="slds-p-around_small">
    <lightning:datatable aura:id="caseLogs"
                         keyField="id"
                         data="{!v.caseEdit}"
                         columns="{!v.columns}"
                         hideCheckboxColumn="false"
                         onrowselection="{!c.doSelectRecord}"
                         onrowaction="{!c.handleRowAction}"
                         draftValues="{!v.draftValues }"
                         onsave="{!c.handleDraftValues}"
                         />
    </div>
</aura:component>

Controller

({
    submitID : function(component, event, helper) {

        var actions = [{
            label : 'Delete',
            name : 'delete',
            iconName : 'action:delete'
        }];


        component.set('v.columns',[
            {label: 'Case Number', fieldName: 'CaseNumber', editable:true},
            {label: 'Case Origin', fieldName: 'Origin', editable:true},
            {label : 'Action', type: "action", typeAttributes : { rowActions : actions }}          
        ]);
            var action = component.get("c.editCase");
            action.setParams({
            'userID': component.get("v.valueInput")
        });   

            action.setCallback(this, function(response){
            var state = response.getState();
            if(state == "SUCCESS"){

            component.set("v.caseEdit", response.getReturnValue());
            }
            else{
            alert('Error in data');
            }
            });
            $A.enqueueAction(action);
            },
            doSelectRecord : function(component, event, helper) {
            var selectedRows = event.getParam('selectedRows');

            },
    handleRowAction : function (component, event, helper){
    var action = event.getParam('action');
    var row = event.getParam('row');

    },



    handleDraftValues: function (component, event, helper) {
        var draftValues = event.getParam('draftValues');
        console.log(draftValues);
        var action = component.get("c.updateCase");
        action.setParams({"upc" : draftValues});
        action.setCallback(this, function(response) {
            var state = response.getState();
            var msg=response.getReturnValue();
            console.log(msg);
            $A.get('e.force:refreshView').fire();

        });
        $A.enqueueAction(action);

    }
})

Apex Class

public class CaseEdit {

    @AuraEnabled

    public static List<Case> editCase(String userID) {
    List<Case> editLog = [Select CaseNumber, Origin
                          From Case where User_ID__c like : userID];
        return editLog;
    }    


@AuraEnabled
    public static string updateCase(List<Case> upc){
        try{
            update upc;
            return 'true';
        } catch(Exception e){
            return e.getMessage();
        }

    }

}

I am sucessfully retreiving the Case details of a particular user using the user ID but I am unable to update the data in it. Whenever I run the code I get the following error:

Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []

Please suggest me a solution for the problem I am facing.

1

For an update DML statement, an Id should be passed in the sobject. To do so, modify the SOQL query and add the Id field. It will flow to the client and then come back to server in the DML statement.

List<Case> editLog = [Select Id,CaseNumber, Origin
                          From Case where User_ID__c like : userID];

Then check the output of console.log(draftvalues) statement. Does the Id value come in the debug statement? If yes then the Id will be passed to server and case will get updated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.