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
Jonathan Wolff 7Jonathan Wolff 7 

Replace manually entered Lightning:select options with automatically populated through picklist

Hello, I have a lightning:select in which I entered all picklist values manually. So it looks like that:
<lightning:select class="ThemaValue" aura:id="ThemaValue" name="Thema" label="Thema" required="false" value="{!v.ThemaValue}">
                            
                            <option value="Alle">Alle</option>
                            <option value="Altersvorsorge">Altersvorsorge</option>          
                            <option value="AOK">AOK</option>
                            <option value="Beratungstag">Beratungstag</option>
                            <option value="Berufsunfähigkeit">Berufsunfähigkeit</option>
                            <option value="bKV">bKV</option>
                            <option 
                            
                        </lightning:select>
Unfortunatly there is a problem, that the values are based on a picklist on my custom object Mediathek named 'Thema__c'. Is there a way to get the values of the picklist as options in my lightning select?

Greetings,
Jonathan
SubratSubrat (Salesforce Developers) 
Hello ,

Yes, you can retrieve the picklist values dynamically from the 'Thema__c' field on your custom object and populate them as options in your <lightning:select> component.

To achieve this, you can make use of the <lightning:inputField> component instead of manually entering the options. The <lightning:inputField> component automatically retrieves the picklist values for a specified field and renders them as options.

Here's an example of how you can modify your code:
<lightning:inputField class="ThemaValue" aura:id="ThemaValue" fieldName="Thema__c" required="false" value="{!v.ThemaValue}" />
In the above code, replace the <lightning:select> component with <lightning:inputField>. Set the fieldName attribute to "Thema__c" to specify the field from which the picklist values should be retrieved.

By doing this, the <lightning:inputField> component will automatically fetch the picklist values for the "Thema__c" field and populate them as options in your component.

Note: The <lightning:inputField> component should be used within a form context, such as <lightning:recordEditForm>, to work properly.

Hope this helps !
Thank you.