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 

autopopulate a custom picklist based on the value of another lookup field

Hi, I am working on a Lightning web component page.I have created a custom lightning page using Lightning web components, having a custom picklist in it, and I am trying to autopopulate the custom picklist on the click of the custom lookup field 'Project'.. Project and Unit is in a Master-detail relationship.

html
<lightning-record-edit-form>
<lightning-card>
<p class="slds-var-p-horizontal_small">
<lightning-record-edit-form object-api-name="Price__c">
<lightning-input-field field-name="Project__c" onchange={projectChange}>
</lightning-input-field>
</lightning-record-edit-form>
<select class="slds-select" >
<option value="Select">Select</option>
<template for:each={options} for:item="option">
<option key={option.label} class="uiInputSelectOption" value={option.value}>{option.value}</option>
</template>
</select>
</p>
</lightning-card>

JS

import { LightningElement , wire, track} from 'lwc';
import getUnit from '@salesforce/apex/PriceFetch.getUnit';
export default class PriceScreen extends LightningElement {
@track options;
projSelected;

projectChange(event) {
this.projSelected = event.detail.value[0];
getUnit({ projId:this.projSelected })
.then(result => { this.options = result; })
.catch(error => { this.options = undefined; }); } }

APEX CLASS

public with sharing class PriceFetch {
@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?
ANUTEJANUTEJ (Salesforce Developers) 
Hi Athira,

Can you try checking this below implementation as it seems to be a one that is similar to the one you have mentioned:

>> https://trailblazers.salesforce.com/answers?id=9063A000000a3gJQAQ

I hope this helps and in case if this comes in handy can you please choose this as best answer so that it can be used by others in the future,

Regards,
Anutej