You need to sign in to do that
Don't have an account?
Itay 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:
LWC.html:
APEX:
So when I go to the logs that's what I see:
And the contact was not updated at all...
Thanks
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:
And the contact was not updated at all...
Thanks
Best Answer chosen by Itay Shechter 10
Itay Shechter 10
SOLVED: To many DML