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
Itay Shechter 10Itay Shechter 10 

Apex update

Hi all,

I'm trying to do a simple record update using lwc that calls apex method and for some reason, the update is not working for me. 

can anyone tell me what I am don't wrong? 

LWC.js:
import { api, LightningElement, track, wire } from 'lwc';
import LightningAlert from 'lightning/alert';
import { getRecord } from 'lightning/uiRecordApi';
import FILESCONFIRMATION_FIELD from '@salesforce/schema/Contact.Files_Confirmation__c'
import updateContactFilesConfirmation from '@salesforce/apex/updateContact.updateContactFilesConfirmation'


export default class DriverFilesAlert extends LightningElement {
    filesConfirm
    @api recordId

    @wire(getRecord, { recordId: '$recordId', fields: [FILESCONFIRMATION_FIELD] })
    accountHandler({ data }) {
        if (data) {
            console.log(data)
            this.filesConfirm = data.fields.Files_Confirmation__c.value
        }
    }

    updateHandler(){
        console.log('updateHandler')
        updateContactFilesConfirmation({contactId:this.recordId})
    }


}

LWC.html:
<template>
    <template if:true={recordId}>
        <lightning-button label="Click" onclick={updateHandler}></lightning-button>
    </template>
</template>

APEX:
public class updateContact {
    @AuraEnabled(cacheable=true)
    public static void updateContactFilesConfirmation(String contactId){
        system.debug('Im at the @updateContactFilesConfirmation@ funcation');
        Contact con = [SELECT Id FROM Contact WHERE Id =: contactId];
        con.LastName = 'test';
        try {
            system.debug('------Try to update----' + con.Id);
            update con;
        } catch (Exception e) {
            system.debug('------Error----');
        }
    }
}

So when I go to the logs that's what I see:
User-added image
And the contact was not updated at all...

Thanks
Best Answer chosen by Itay Shechter 10
Itay Shechter 10Itay Shechter 10
SOLVED: To many DML