Upon inserting some sample record, I noticed that only the Name field has been inserted, while Object A lookup field does not have any value. I checked log via browser's developer console and id of the inserted record is recorded. But when I visit the record's detail page on Salesforce, the lookup field does not have any value at all. How can I insert the selected record from the lookup field?

Here are the codes that I am stuck with:


    <lightning-record-edit-form object-api-name={childObjectApiName}>
        <label for="fieldid">{fieldLabel}</label>
        <lightning-input-field id="fieldid" required={required} variant="label-hidden" field-name={targetFieldApiName}
            value={value} onchange={handleChange} disabled={disabled}>


import { LightningElement, api } from 'lwc';

export default class CustomLookup extends LightningElement {
    @api childObjectApiName = 'Custom_Object__c'; 
    @api targetFieldApiName = 'ObjectA__c'; 

    @api fieldLabel = 'Your field label here';
    @api disabled = false;
    @api value;

    @api required = false;

    handleChange(event) {
        const selectedEvent = new CustomEvent('valueselected', {
            detail: event.detail.value[0]

    @api isValid() {
        if (this.required) {


<!--portion of main page-->
    <lightning-input type="text" 
        label="Custom Object Name"

    <c-custom-lookup field-label="Object A" 



import { LightningElement, track, wire } from 'lwc';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
import CUSTOM_OBJECT from '@salesforce/schema/Custom_Object__c';

import createCustomObj from '@salesforce/apex/CustomObjectController.createCustomObj';
    export default class customObjLWC extends LightningElement {

    @track custObjRecord = {Custom_Object__c:""};

    handleCustObjNameChange(event) {
        this.custObjRecord.Name = event.detail.value;
        console.log('Custom Object Name' + this.custObjRecord.Name);

    handleObjectAChange(event) {
        this.custObjRecord.ObjectA__c = event.detail;
        console.log('Object A' + this.custObjRecord.ObjectA__c);

    validateLookupField() {

    createRecord() {

            newCustObj: this.custObjRecord
        .then(result => {
            this.custObjRecord = {};

            this.dispatchEvent(new ShowToastEvent({
                title: 'Success!!',
                message: 'Custom Object Record Created Successfully!!',
                variant: 'success'
        .catch(error => {
            this.error = error;


public with sharing class CustomObjectController {

    public static Custom_Object__c createCustomObj(Custom_Object__c newCustObj) {
       insert newCustObj;
       return newCustObj;

Would appreciate if anyone could help me on this. Thanks in advance!


Use event.detail.value[0] to get the recordId of the selected record. Value of lookup field is an array.

handleChange(event) {
    const selectedEvent = new CustomEvent('valueselected', {
        detail: event.detail.value[0]
  • I modified the customLookup.js, but there is still no lookup field value when I checked the record detail page upon creation. – Ertyq Jul 3 '20 at 4:59
  • Have you got the id in co console.log? – Rahul Gawale Jul 3 '20 at 5:10
  • Yes, id is still displaying in console.log – Ertyq Jul 3 '20 at 5:13
  • also check the fls for that field – Rahul Gawale Jul 3 '20 at 5:19
  • 1
    Field is visible to all profiles, and value is inserting when I use Salesforce standard creation page. – Ertyq Jul 3 '20 at 5:55

Is the lookup part of the default page layout for the profile accessing your LWC? There seems to be a "feature" or Record Edit Form that Lookup fields do not work correctly unless they are on the page layout, See https://help.salesforce.com/articleView?id=000349125&language=en_US&mode=1&type=1

update: It is also being tracked as a Known Issue since Winter 19, status "In Review": https://trailblazer.salesforce.com/issues_view?id=a1p3A000001RWq7QAG

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.