I am looking to have a lightning web component that returns data from an object based on the record I am on that i can display on a lightning record page . I am exploring programmatically pulling a custom metadata type record so that it can be configurable. I have created the custom metadata type record already.

I am aware that in addition the Lightning web component, I need an apex class in order to query the custom metadata type and data. I wish i could do this all with a LWC, but when i do that, i can only return the actual value in the Custom metadata type and not the actual object's dynamic field.

Example: I would like to return the Case object's field "Subject" in the lightning component along with some static text. e.g. (if the Case's subject = "Urgent Matter" then on the case record, i want that to show) any help is appreciated around the apex part - thanks!

so far in my apex class i have:

public with sharing class Case_Name {
public static void getCaseMetaData(Id recordId){

    String sObjectName = recordId.getSObjectType().getDescribe().getName();
    List<string> fields = new List<string>();
    List<Case_Name__mdt> caseName = [SELECT Id, DeveloperName, Text__c, Text_Fields__c, from Case_Name__mdt where DeveloperName = 'Casename'];
  • You can use getRecord by simply having a record Id and the fields you want, and you can getObjectInfo to get fields, etc.
    – sfdcfox
    Mar 25, 2021 at 4:58
  • Thank you- i have used getrecord in my LWC but am wanting to pull custom metadata types so it can be configurable by a Salesforce Admin if they want to change the output without touching the code. is it possible to do this still with just a LWC to pull the field's data with custom metadatatype? Mar 25, 2021 at 5:02
  • You could, yes, using getRecord and getObjectInfo.
    – sfdcfox
    Mar 25, 2021 at 5:15
  • 2
    You could also just use the XML configuration file to allow admins to pass properties into your LWC in record pages, communities, home page, etc, via lightning app builder / community builder: developer.salesforce.com/docs/component-library/documentation/… Mar 25, 2021 at 6:11


You must log in to answer this question.