While creating a custom object record using LWC with two values Name and Customer (look up to Account), encountering below error:
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_TYPE_ON_FIELD_IN_RECORD, Customer: value not of required type: [0011H000023s57sQAA]: [Customer__c]
BM_Servicehelper.cls
public with sharing class BM_Servicehelper {
@AuraEnabled
public static string inserRcd(BM_Service__c serviceObj){
insert serviceObj;
}
}
serviceUIActLwc.js
import { LightningElement,wire,api } from 'lwc';
import SERVICE_OBJECT from '@salesforce/schema/BM_Service__c';
import insertServiceRcd from '@salesforce/apex/BM_Servicehelper.inserRcd';
export default class ServiceUIActLwc extends NavigationMixin(LightningElement) {
@api serviceRcd = SERVICE_OBJECT;
@api selectedAccRecordId;
@api serviceName;
serviceNameChngHandler(event){
//Entered Service Name
this.serviceName = event.target.value;
}
selActRcdHandler(event) {
//account record selected ID value picked - used custom look logic to get ID
this.selectedRecordId = event.detail;
}
//Save Button action
saveActionHandler(){
//Calling apex method with 2 parameters in object BM_Service__c
this.serviceRcd.Name this.serviceName; //Name of Service Record
this.serviceRcd.Customer__c = this.selectedAccRecordId; // Lookup field to Account
insertServiceRcd({
serviceObj : this.serviceRcd
}).then(result=>{
alert('Success::');
}).catch((error)=>{
alert('Error:::');
});
}
}
{}
tool in the editor or triple backticks (```) to format your code.event.detail
inselActRcdHandler(event)
. Since there is a custom logic I'd suggest to double check what is passed from there. Also, what is the reason for using custom logic? It might be easier with something standard