Implementing Custom Metadata in LWC Without Apex

Custom Metadata Offers excellent flexibility to administrators and developers for crafting dynamic functionalities. In the context of Lightning Web Components, a common query is how custom metadata records can be efficiently accessed. The answer is that there is no need for an Apex call to retrieve your custom metadata records in Lightning Web Components.

Obtaining Custom Metadata in Lightning Web Components without Using Apex

Utilize the wire service and the getRecord wire adapter to retrieve record data in a Lightning Web Component. Let’s create a component named “lifeCycle” to obtain the custom metadata record without invoking an Apex method and display the value on the UI. Begin by creating a custom metadata in the developer org with the API name “Validation_Control__mdt,” which includes a custom field with the API name “isActive__c.

After creating the custom metadata object, a corresponding record has been generated. In the component’s JavaScript file, I have manually set the record ID for retrieval. Alternatively, you can dynamically pass the ID.


    <lightning-card title="My Custom Metadata" icon-name="standard:contact">
        <template if:true={}>
            <div class="slds-m-around_medium">


First, the code imports the getRecord wire adapter from the lightning/uiRecordApi module, which is built on Lightning Data Service. Then it defines the fields to pass to the wire adapter.

The @wire decorator tells getRecord to get the values of the specified fields on the record with the specified $recordId. The $ means that the value is passed dynamically. When the value changes, the wire service provisions data and the component rerenders.The data is provisioned to the data and error objects of the property decorated with @wire.

import { LightningElement, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
const FIELDS = [

export default class LifeCycle extends LightningElement {
    //Id is hardcoded for demo purpose. You can pass a dynamic id here

    @wire(getRecord, { recordId: '$recordId', fields: FIELDS })
    get label() {

    get developername() {

    get active() {

    get language() {


<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="">


Include your component on the screen by editing the Lightning page. The components mentioned above can be added to the Home page, app, or record page as specified in the lifeCycle.js-meta.xml file.

How to get Custom Metadata in Lightning Web Component without Apex?