Custom Metadata in LWC without Apex

Custom Metadata provides a great flexibility to admins and developer to write and create a dynamic functionality. When it comes to Lightning Web Component, the question arises how efficiently custom metadata record can be accessed in it. The answer is you don’t need an apex call to get your custom metadata record in Lightning Web Component.

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

You can use the wire service to get record data. To get the data, the Lightning Web Component uses the getRecord wire adapter.

Let’s create a Component with name lifeCycle to get the custom metadata record without calling an apex method and show the value on UI. First Create a custom metadata in the developer org. The Api name is Validation_Control__mdt. It also has a custom field with Api name isActive__c.

Once custom metadata object has been created, we also have created a record of it. I have hard coded the record-id in the component JavaScript file to get the record. You can dynamically pass the id.

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


    <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="">


Add your component anywhere on the screen by editing the lightning page. The above components can be added to Home page, app or record page according to lifeCycle.js-meta.xml file.

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


Leave a Comment