Project and Unit in a Master-detail relationship Project-Master object Unit - detail object Price - another custom object Price contains two custom lookup fields Project, Unit I have created a custom input form for 'Price' object using lightning web components. I had defined the fields Project, Unit as:

 <lightning-input-field field-name="Unit__c" value ={unitVal}>

But when I did so, all projects got listed out in 'Project' field, but 'Unit' field is empty And also the filter is not working, I need to filter the values of 'Unit' that comes under the selected project.


projectChange(event) {
   this.projSelected = event.detail.value[0];

   getUnit({ projId:this.projSelected })

   .then(result => {

    this.unitVal = result;

   .catch(error => {
    this.unitVal = undefined;


Apex class

@AuraEnabled(cacheable = true) public static List<Unit__c> getUnit(Id projId) {

    return [SELECT Id,  Name FROM Unit__c where Project__c = :projId ];

Is there any mistake in my code?
<lightning-input-field field-name="Unit__c" value ={unitVal}>

In your code, you have used the unit records list for the "value" attribute, but lightning-input-field will not admit that. You can only provide the Id of any unit record to the "value" attribute.

Besides, you can show the unit records in a custom picklist and get the Id of the selected unit record and provide it to the "Unit__c" field of the project at the time of submit of the project record.

  • Hi Avi, is there any other way to do this? Sep 29 '20 at 6:44
  • Either you can go for a custom picklist to show Unit records or go with the custom LookUp component.
    – Avi Rai
    Sep 29 '20 at 7:48
  • Is it possible using a lightning:combobox? Sep 29 '20 at 10:13
  • Yes, that is good.
    – Avi Rai
    Sep 29 '20 at 14:41

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.