1

I want to get custom settings or custom metadata types in lightning web components for creating reusable component. Can anyone suggest me how to get custom metadata types or settings records using getRecord API of LWC.

2

You can define your template like below

<template>
    <lightning-card title="Sample custom Metadata" icon-name="standard:contact">
        <template if:true={metadataRecord.data}>
            <div class="slds-m-around_medium">
                <p>{label}</p>
                <p>{developername}</p>               
            </div>
        </template>
    </lightning-card>
</template>

and in your js like this

import { LightningElement, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
const FIELDS = [
    'TheCustomMetadata.MasterLabel',
    'TheCustomMetadata.DeveloperName'
];

export default class CustomMetadataApp extends LightningElement {
   
    recordId;

    @wire(getRecord, { recordId: '$recordId', fields: FIELDS })
    metadataRecord;
    
    get label() {
        return this.metadataRecord.data.fields.MasterLabel.value;
    }

    get developername() {
        return this.metadataRecord.data.fields.DeveloperName.value;
    }
}
3
  • how to get list type of custom metadata or settings? @Klecool Jun 24 '20 at 12:56
  • I tried with above code snippet response is undefined @Klecool Jun 24 '20 at 13:01
  • Unfortunately there is no way in LWC to get custom settings. you can also look at this link
    – Klecool
    Jun 24 '20 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.