Why is Lightning-Combobox not showing the dropdown list?

615    Asked by elonji_3393 in Salesforce , Asked on May 12, 2023

 I'm building a lwc combobox with calling Apex method. What I want to do is to show all field labels of Account in a dropdown list. I confirmed the lwc receives the value from Apex method but my lwc doesn't show anything if I clicked the button as follows:

Here's my JS code:

import { LightningElement,track, wire } from 'lwc'; import retrieveFields from '@salesforce/apex/RetrieveShinseiFields.retrieveFields'; export default class DisplayShinseiFields extends LightningElement { @track fieldsInfo=[]; @track obj; value; @wire(retrieveFields) wiredLabels({error, data}){ if(data){ for(var key in data){ this.obj={label:key, value:data[key]}; this.fieldsInfo.push(this.obj); } } if(error){ this.error=error; } } handleChange(event) { this.value = event.detail.value; } }
And the Apex class:
public with sharing class RetrieveShinseiFields { @AuraEnabled(cacheable=true) public static Map retrieveFields(){ Map fields = Account.getSObjectType().getDescribe().fields.getMap(); Map fInfo = new Map(); for(SObjectField f : fields.values()) { string fLabel = f.getDescribe().getLabel(); string fName = f.getDescribe().getName(); fInfo.put(fLabel, fName); } System.debug(finfo); return fInfo; } }
My html
Answered by Ella Clarkson

If the lightning-combobox is not showing the dropdown list -

HTML CODE:


JS Code:
import { LightningElement,track, wire } from 'lwc'; import retrieveFields from '@salesforce/apex/RetrieveShinseiFields.retrieveFields'; import SystemModstamp from '@salesforce/schema/Account.SystemModstamp'; export default class DisplayShinseiFields extends LightningElement { @track fieldsInfo=[]; @track obj; value; loaded = false @wire(retrieveFields) wiredLabels({error, data}){ if(data){ console.log('data '+JSON.stringify(data)) for(var key in data){ console.log('this.obj '+JSON.stringify({label:key, value:data[key]})) this.fieldsInfo.push({label:key, value:data[key]}); } this.loaded = true; } if(error){ this.error=error; } } handleChange(event) { this.value = event.detail.value; } }
The fieldsInfo array needs to be updated before being rendered.

Your Answer

Interviews

Parent Categories