0

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:::');
        });
    }

}
4
  • 2
    Welcome to SFSE. Please use the {} tool in the editor or triple backticks (```) to format your code.
    – David Reed
    Commented Jul 11, 2020 at 18:46
  • Please log what is stored in event.detail in selActRcdHandler(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
    – nchursin
    Commented Jul 11, 2020 at 20:24
  • It is picking Customer ID(Account) like '0011H000023s57sQAA'. I tried to hard code the value and pass back end it worked. when I m passing as parameter it is not supported.
    – Akash
    Commented Jul 12, 2020 at 5:20
  • 1
    Can you check that if you have lookup filters on that field? Commented Jul 13, 2020 at 13:19

0

You must log in to answer this question.