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
Mahesh SMahesh S 

Display Apex controller result in Dropdown list in LWC

Hello LWC experts, 

I'm facing issue display the Apex controller result in LWC. so i want to display in the form of dropdown list in my LWC. can someone please help with this and Thank you in Advacnce 

Apex: 

    @AuraEnabled(cacheable=true)
    public static List<InsurancePolicyParticipant> showOnlyBDIpolicy(string AccountId){
        return [SELECT Id, InsurancePolicy.Name FROM InsurancePolicyParticipant
                    WHERE PrimaryParticipantAccountId =: clientId];
    }


JS file:

    get productNumberOptions(){
        console.log('***  '+JSON.stringify(this.productOptions))
        return this.productOptions;
    }

    handleProductChange(event){
        this.productNumber = event.detail.value;
    }
    @wire(displayBDIpolicy, {AccountId: '$recordId'} )
    wiredBDIpolicy({error, data}){
        if(data){
            console.log('$$$$  '+JSON.stringify(data))
            for(let i = 0; i < data.length; i++){
                this.productOptions.push({ label: data[i].InsurancePolicy.Name, value: data[i].Id });
            }
            console.log(JSON.stringify(this.productOptions));
        }
        if(error){
            console.log(error);
            showToast(this, 'error', error);
            }
    }

HTML file:

                <lightning-layout-item size="4" padding="around-small" >
                    <lightning-combobox label={LABEL.PRODUCTNUMBER} placeholder={LABEL.PRODUCTNUMBER} value="NAmnea 231e" options={productNumberOptions} required onchange={handleProductChange}></lightning-combobox>
                </lightning-layout-item>

 

User-added image