+ Start a Discussion
Pavushetti Abhilash 3Pavushetti Abhilash 3 

update field value when user click on button

Hi everyone.
There is button in lwc datatable column. When user clicks on button the field value should update. (field is checkbox, it should check). WHEN BUTTON IS ON THE APPROVAL STATUS FIELD SHOULD CHECK . Its not working. Please let me know where I am doing mistake. Please refer my lwc html, JS and apex.
HTML--------
<c-custom-type-component draft-values={draftValues}  
                                show-row-number-column 
                                onsave={handleSave} 
                                key-field="Id" 
                                data={caseLineItems} 
                                columns={columns}
                                hide-checkbox-column="true"
                                onrowselection={updateSelected}
                                onrowaction={callRowAction} 
                                 onselectedrec={handleSelectedRec}>
             </c-custom-type-component>
-----------JS------------------
import getSelectedCaseLineItems from '@salesforce/apex/rmaCaseLineItemController.getSelectedCaseLineItems';
import updateToggle from '@salesforce/apex/rmaCaseLineItemController.updateToggle';

const columns = [ 
{ label: 'Approval Status', fieldName: 'Approval_status__c', type: 'toggleButton', disabled: false, initialWidth: 120,
           typeAttributes: { 
                buttonDisabled: { fieldName:'Approval_status__c' }, 
                rowId: { fieldName: 'getrowIs' }, 
            }
        }
]
handleSelectedRec(event){
         const {value}=event.detail
         this.saveCase = true;
        console.log("Hello",value);
        this.currentRecordId=event.target.value;
        console.log('@@currentRecordId@@@'+this.currentRecordId);
        updateToggle({cliId: this.currentRecordId})
          .then(() => {
            console.log('SUCCESS');
            return refreshApex(this.caseLineItems);
        })
        .catch((error) => {
            this.errorMessage=error;
            console.log('unable to update the record due to'+JSON.stringify(this.errorMessage));
        });
    }
---------------APEX CLASS-------------
public with sharing class rmaCaseLineItemController {
    @AuraEnabled(cacheable=true)
    public static List<R4C_Case_Line_Item__c> getSelectedCaseLineItems(string caseid){
        return [SELECT ID,PO__c,Name,Remedy__c,Return_Reason__c,Return_Type__c,Stocking__r.Name,Stocking__c,MMID_BU_Hierarchy__c,MMID_BU_Hierarchy__r.Name, Approval_status__c, 
                SO__c, PO_Date__c,Sold_To__r.Name,Ship_To__r.Name,Sold_To__c,Ship_To__c,Line_Item__c,
                MMID__r.Name,Quantity__c,Return_Quantity__c,Billed_Quantity__c,Net_Value__c, 
                Intel_Product_Name__c, Stocking_ID__r.Name, Customer_Part_Number__c
                FROM R4C_Case_Line_Item__c where Case__r.Id = :caseid];
    }
@AuraEnabled
   public static R4C_Case_Line_Item__c updateToggle(String cliId){
       System.debug('Cli' +cliId);
       R4C_Case_Line_Item__c cli=[select Id,Approval_status__c from R4C_Case_Line_Item__c where Id=:cliId];
       cli.Approval_status__c= True;
       try{
           update cli;
       }
       catch (Exception e) {
           System.debug('unable to update the record due to'+e.getMessage());
       }
       return cli;
   }
}