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
Athira VenugopalAthira Venugopal 

unable to insert Look up custom fields into a custom object

Here is my entire code, I am working in Visual studio code 
I have created a custom object 'Price', having two custom look up fields (Project, Unit) and some other fields,. I am trying to insert values into this custom object, but the look up field values(Project, Unit) are not getting inserted, all other fields got inserted.

Html template
<template>
  <lightning-card>
          <p class="slds-var-p-horizontal_small">

            <lightning-input label="Date" name="datefld" type="date" value={fDate} onchange={handledChange} ></lightning-input>
            <lightning-input label="Enquirer" name="enquiry" type="textarea" value={enq} onchange={handledChange} ></lightning-input>
    <lightning-record-edit-form object-api-name="Price__c">
    <lightning-input-field field-name="Project__c" required onchange={projectChange}>
    </lightning-input-field>
    </lightning-record-edit-form>
    <lightning-record-edit-form object-api-name="Price__c">
        <lightning-input-field field-name="Unit__c"  onchange={unitChange}>
        </lightning-input-field>
        </lightning-record-edit-form>
    
    
   <lightning-input label="Unit Rate" name="rate" type="Double" value={rNumber} onchange={handledChange}></lightning-input>
    <lightning-input label="Additional cost" name="cost" type="Double" value={cNumber} onchange={handledChange}></lightning-input>
    <lightning-input label="Discount" name="dis" type="Double" value={dNumber} onchange={handledChange}></lightning-input>
    <lightning-input label="Agreement cost" name="agree" type="Double" value={aNumber} onchange={handledChange}></lightning-input>
    <lightning-input label="Remarks" name = "remark" type="textarea" value={resultsum} onchange={handledChange}></lightning-input> 
    
     <lightning-button label="Save" onclick={handleClick}></lightning-button>
    
    
           </p>
           </lightning-card>
</template>

JS
import { LightningElement ,api, wire, track} from 'lwc';

import newPrice from '@salesforce/apex/PriceFetch.newPrice';
export default class PriceScreen extends LightningElement {
    datefld;
    enquiry;
    projSelected;
    unitSelected;
    rate;
    cost;
    dis;
    agree;
    remark;
 
    handledChange(event){

        if(event.target.name==='datefld'){

            console.log('handle Change'+event.target.value);

            this.datefld = event.target.value;

        }
        else if(event.target.name==='enquiry'){

            console.log('handle Change'+event.target.value)

            this.enquiry = event.target.value;    
       }

        else if(event.target.name==='rate'){

            console.log('handle Change'+event.target.value)

            this.rate = event.target.value;    
       }
       else if(event.target.name==='cost'){

        console.log('handle Change'+event.target.value)

        this.cost = event.target.value;    

    }
    else if(event.target.name==='dis'){

        console.log('handle Change'+event.target.value)

        this.dis = event.target.value;    
        
   
    }
    else if(event.target.name==='agree'){

        console.log('handle Change'+event.target.value)

        this.agree = event.target.value;    

    }
    else if(event.target.name==='remark'){

        console.log('handle Change'+event.target.value)

        this.remark = event.target.value;    

    }
    }
    projectChange(event) {
        projSelected = event.detail;
    }
    unitChange(event) {
        unitSelected = event.detail;
    }
   handleClick(event) {
        newPrice({ entryDate: this.datefld, enqName : this.enquiry, proj:projSelected, unit:unitSelected,
             unitRate:this.rate, addtnlCost:this.cost, discount:this.dis, agreeCost:this.agree,rem:this.remark })

        .then(result => {

            this.result = result;
           if(this.result == 'true') {
               alert("SUCCESS");
           }
        })
        .catch(error => {
             this.error = error;
             alert("FAILURE" + error);
              //this.error = error;
        });
    }
}
PriceFetch.cls (Apex controler class)
public with sharing class PriceFetch {
  
 
    @AuraEnabled
    public static Boolean newPrice(Date entryDate, String enqName, Id proj, Id unit,Double unitRate,Double addtnlCost, Double discount,Double agreeCost, String rem ){
     
       Price__c price = new Price__c();
       price.Date__c = entryDate;
       price.Name = enqName;
       price.Project__c = proj;
       price.Unit__c = unit;
       price.Unit_Rate__c = unitRate;
       price.Additional_cost__c = addtnlCost;
       price.Discount__c = discount;
       price.Agreement_cost__c = agreeCost;
       price.Remarks__c = rem;
       try {
        insert price;
        return true;
           
       } catch (Exception e) {
           throw new AuraHandledException('exceptionText' + e.getMessage());
         
       }
      
    }
}


Is there any mistake in my code
 
ShirishaShirisha (Salesforce Developers) 
Hi Athira,

Greetings!

Please be informed that there is no standard lookup component available in lightning yet. but with <lightning:inputField> component you can use show lookup in your lightning component.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_lightning_inputField.htm?search_text=lookup
else you have need to create custom lookup component
here is the link for custom resuable lookup component :
http://sfdcmonkey.com/2017/07/17/re-usable-custom-lookup/

Hope it will helps you, kinldy let us know if it helps you.

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri