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
Luciano RobertoLuciano Roberto 

How do I list the items in a metadata in a picklist of component Lightning ?

Good afternoon people,

I have a list of records in a custom metadata and need to list them in a pickilist of a form of a component that I'm creating. Could someone help me with a code?

Thanks

 

Best Answer chosen by Luciano Roberto
karthikeyan perumalkarthikeyan perumal
kinldy refer this link for Custom setting metadata which is used in lightning component.

https://sfcure.com/2018/05/28/how-to-create-update-custom-metadata-record-using-apex-lightning-component/

Thanks
karthik
 

All Answers

karthikeyan perumalkarthikeyan perumal
Hello, 

Try Below Code, 

Class: 

"rajam_karthik__Test_Custom_MD__mdt" -- Replace you custom Metadate Type API Name.
public with sharing class Cust_mtd_Class {

List<selectOption> options = new List<selectOption>();
public List<selectOption> getmtdvalue() {
for(rajam_karthik__Test_Custom_MD__mdt samplemtd: [Select DeveloperName ,MasterLabel from rajam_karthik__Test_Custom_MD__mdt])
{
options.add(new selectOption(samplemtd.MasterLabel ,samplemtd.MasterLabel ));
}
return options;
}

}

Visualfroce page: 
 
<apex:page sidebar="false" controller="Cust_mtd_Class">
<apex:form >
<apex:selectList multiselect="false" size="1">
<apex:selectOptions value="{!mtdvalue}">
</apex:selectOptions>
</apex:selectList>
</apex:form>
</apex:page>

Hope this will help you. 

Thanks
karthik

 
Luciano RobertoLuciano Roberto
Thanks for the answer, but it is not for visualforce page, I need to do by component Lgihtning salesforce
karthikeyan perumalkarthikeyan perumal
kinldy refer this link for Custom setting metadata which is used in lightning component.

https://sfcure.com/2018/05/28/how-to-create-update-custom-metadata-record-using-apex-lightning-component/

Thanks
karthik
 
This was selected as the best answer