Hey guys, today in this post we are going to learn about How to fetch/Edit Custom Metadata Type Records Uses of lightning:datatable and onrowaction operation in Lightning Component Salesforce.
What is the difference between Custom Settings and Custom Metadata Types
To know more details about what is difference between Custom Settings and Custom Metadata, Click Here..
Files we used to fetch/Edit Custom Metadata and display in aura component in Salesforce
customMetadataCmp.cmp | Lightning Component | It is used for create a table and fetch/edit custom metadata values in lightning component |
customMetadataCmpController.js | JavaScript Controller | It is hold Javascript Init function to fetch the records from server |
customMetadataCmpHelper.js | JavaScript Controller Helper | It is hold for Javascript Helper Function to get Custom Metadata values from apex method. |
customMetadataCtrl.apxc | Apex Controller | It is used for get the custom metadata record type values from Apex Class Method |
customMetadataApp.app | Lightning Application | It is used for call the component and preview on browser. |
Custom Metadata API:- customMetadataIntegrate__mdt | Fields of Custom Metadata record type:- MasterLabel, Active__c, Api_Endpoint__c, Bucket__c, Call_Back_URL__c, Folder__c |
Real time scenarios:- Get the Custom Metadata Type Records from server side and display the record on edit view on popup through onrowaction click functionality in lightning component controller JavaScript.
Final Output
You can download file directly from github by Click Here.
Other related post that would you like to learn in Salesforce
- Find the below steps
Create Lightning Component
Step 1:- Create Lightning Component : customMetadataCmp.cmp
From Developer Console >> File >> New >> Lightning Component
customMetadataCmp.cmp [Lightning Component File]
![]() |
<aura:component controller="customMetadataCtrl" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="metaList" type="customMetadataIntegrate__mdt[]"/>
<aura:attribute name="data" type="Object"/>
<aura:attribute name="columns" type="List"/>
<aura:attribute name="record" type="Object"/>
<div class="slds slds-p-around--medium">
<lightning:card variant="Narrow" title="Metadata Action Row" iconName="custom:custom66">
<lightning:datatable columns="{! v.columns }"
data="{! v.data }"
keyField="id"
onrowaction="{! c.metaActionRow}"
hideCheckboxColumn="true"/>
</lightning:card>
<div class="slds-hide" aura:id="metaRowPopupId" style="height: 340px; ">
<section class="slds-modal slds-fade-in-open">
<div class="slds-modal__container">
<header class="slds-modal__header">
<button class="slds-button slds-button_icon slds-modal__close slds-button_icon-inverse" onclick="{!c.handleCancelPopupClick }" title="Close">
<lightning:icon iconName="utility:close" alternativeText="Approved" />
</button>
<h2 class="slds-text-heading_medium slds-hyphenate">Metadata Action Row</h2>
</header>
<div class="slds-modal__content slds-p-around_medium">
<div class="slds-form slds-form_stacked">
<div class="slds-form-element">
<lightning:input type="text" name="MasterLabel" label="MasterLabel" value="{!v.record.MasterLabel}"/>
</div>
<div class="slds-form-element">
<lightning:input type="text" name="ApiEndpoint" label="Api Endpoint" value="{!v.record.Api_Endpoint__c}"/>
</div>
<div class="slds-form-element__control" >
<lightning:input type="text" label="Bucket" name="Bucket" value="{!v.record.Bucket__c}"/>
</div>
<div class="slds-form-element__control" >
<lightning:input type="text" label="Call Back URL" name="CallBackURL" value="{!v.record.Call_Back_URL__c}"/>
</div>
<div class="slds-form-element__control" >
<lightning:input type="text" label="Active" name="Active" value="{!v.record.Active__c}"/>
</div>
</div>
</div>
<footer class="slds-modal__footer">
<lightning:button class="slds-button slds-button_destructive" label="Cancel" title="Cancel" onclick="{! c.handleCancelPopupClick }"/>
</footer>
</div>
</section>
<div class="slds-backdrop slds-backdrop_open"></div>
</div>
<br/>
<!--Start RelatedTopics Section-->
<div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
<p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/05/thumbsUpLike.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:16px; font-style:italic; display:inline-block; margin-right:5px;">Don't forget to check out:-</span><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer" style="text-decoration:none;" data-aura-rendered-by="440:0">An easy way to learn step-by-step online free Salesforce tutorial, To know more Click <span style="color:#ff8000; font-size:18px;" data-aura-rendered-by="442:0">Here..</span></a></strong></p>
<br/><br/>
<p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/07/tickMarkIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:17px; font-style:italic; display:inline-block; margin-right:5px; color:rgb(255 128 0);">You May Also Like β</span> </strong></p>
<div style="display:block; overflow:hidden;">
<div style="width: 50%; float:left; display:inline-block">
<ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;">
<li><a href="https://www.w3web.net/lwc-get-set-lightning-checkbox-value/" target="_blank" rel="noopener noreferrer">How to get selected checkbox value in lwc</a></li>
<li><a href="https://www.w3web.net/display-account-related-contacts-in-lwc/" target="_blank" rel="noopener noreferrer">how to display account related contacts based on AccountId in lwc</a></li>
<li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to create lightning datatable row actions in lwc</a></li>
<li><a href="https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank" rel="noopener noreferrer">how to use if and else condition in lwc</a></li>
<li><a href="https://www.w3web.net/get-selected-radio-button-value-and-checked-default-in-lwc/" target="_blank" rel="noopener noreferrer">how to display selected radio button value in lwc</a></li>
</ul>
</div>
<div style="width: 50%; float:left; display:inline-block">
<ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;">
<li><a href="https://www.w3web.net/display-account-related-contacts-lwc/" target="_blank" rel="noopener noreferrer">display account related contacts based on account name in lwc</a></li>
<li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to insert a record of account Using apex class in LWC</a></li>
<li><a href="https://www.w3web.net/fetch-picklist-values-dynamic-in-lwc/" target="_blank" rel="noopener noreferrer">how to get picklist values dynamically in lwc</a></li>
<li><a href="https://www.w3web.net/edit-save-and-remove-rows-dynamically-in-lightning-component/" target="_blank" rel="noopener noreferrer">how to edit/save row dynamically in lightning component</a></li>
<li><a href="https://www.w3web.net/update-parent-object-from-child/" target="_blank" rel="noopener noreferrer">update parent field from child using apex trigger</a></li>
</ul>
</div>
<div style="clear:both;"></div>
<br/>
<div class="youtubeIcon">
<a href="https://www.youtube.com/channel/UCW62gTen2zniILj9xE6LmOg" target="_blank" rel="noopener noreferrer"><img src="https://www.w3web.net/wp-content/uploads/2021/11/youtubeIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;"/> <strong>TechW3web:-</strong> To know more, Use this <span style="color: #ff8000; font-weight: bold;">Link</span> </a>
</div>
</div>
</div>
<!--End RelatedTopics Section-->
</div>
</aura:component>
Create JavaScript Controller
Step 2:- Create Lightning Component : customMetadataCmpController.js
From Developer Console >> File >> New >> Lightning Component >> JavaScript Controller
customMetadataCmpController.js [JavaScript Controller]
![]() |
({
doInit : function(component, event, helper) {
helper.initHelper(component, event, helper);
},
metaActionRow: function ( component, event, helper ) {
var action = event.getParam('action');
var row = event.getParam('row');
//alert('row ' + JSON.stringify(row));
switch (action.name) {
case 'edit_record':
component.set( "v.record", row );
var metaEle = component.find( "metaRowPopupId" );
$A.util.removeClass( metaEle, "slds-hide" );
break;
}
},
handleCancelPopupClick: function( component, event, helper ){
var metaEle = component.find( "metaRowPopupId" );
$A.util.addClass( metaEle, "slds-hide" );
},
})
Create JavaScript Helper
Step 3:- Create Lightning Component : customMetadataCmpHelper.js
From Developer Console >> File >> New >> Lightning Component >> JavaScript Helper
customMetadataCmpHelper.js [JavaScript Helper File]
![]() |
({
initHelper : function(component, event, helper) {
let rowActions = [{
'label': 'Edit',
'iconName': 'action:edit',
'name': 'edit_record'
}];
let columns = [
{ label: 'MasterLabel', fieldName: 'MasterLabel', type: 'text' },
{ label: 'Api Endpoint', fieldName: 'Api_Endpoint__c', type: 'url' },
{ label: 'Bucket', fieldName: 'Bucket__c', type: 'text'},
{ label: 'Call Back URL', fieldName: 'Call_Back_URL__c', type: 'url'},
{ label: 'Active', fieldName: 'Active__c', type: 'text'},
{ type: 'action', typeAttributes: { rowActions: rowActions } }
];
component.set( "v.columns", columns );
helper.retrieveDataHelper( component );
},
retrieveDataHelper : function( component ) {
var action = component.get("c.customMetaObj");
action.setCallback( this, function( response ) {
var state = response.getState();
if( state === "SUCCESS") {
var result = response.getReturnValue();
//alert('result' + JSON.stringify(result));
//console.log( response.getReturnValue() );
component.set( "v.data", result );
}
else if (state === "INCOMPLETE") {
alert('Error in the response');
}
else if (state === "ERROR") {
var errors = response.getError();
if (errors) {
if (errors[0] && errors[0].message) {
console.log("Error message: " +
errors[0].message);
}
} else {
console.log("Unknown error");
}
}
});
$A.enqueueAction( action );
},
})
Create Apex Class Controller
Step 4:- Create Apex Class : customMetadataCtrl.apxc
From Developer Console >> File >> New >> Apex Class
customMetadataCtrl.apxc [Apex Class Controller]
![]() |
public class customMetadataCtrl {
@AuraEnabled
public static List<customMetadataIntegrate__mdt> customMetaObj(){
List<customMetadataIntegrate__mdt> metaObj = [SELECT Id, MasterLabel, Api_Endpoint__c, Bucket__c, Call_Back_URL__c, Folder__c, Active__c FROM customMetadataIntegrate__mdt];
system.debug('metaObj#__11 ' + metaObj);
RETURN metaObj;
}
}
Create Lightning Application
Step 5:- Create Lightning Application : customMetadataApp.app
From Developer Console >> File >> New >> Lightning Application
customMetadataApp.app [Component Application File]
![]() |
<aura:application extends="force:slds">
<c:customMetadataCmp/>
</aura:application>
Further post that would you like to learn in Salesforce
How do I add custom metadata to Salesforce?
From the App Picker, select Custom Metadata Loader. Click the Custom Metadata Loader tab. If you haven't already done so, the app prompts you to configure your Remote Site Settings.
What are the types of metadata?
There are Three (3) different types of metadata: descriptive, structural, and administrative.
Where is metadata stored?
Metadata is stored in two main places:- 1) Internally 2) Externally
What is the difference between data and metadata?
The main difference between Data and Metadata is that data is simply the content that can provide a description, measurement and metadata describes the relevant information on said data, giving them more context for data users.
Related Topics | You May Also Like
Our Free Courses β
π Get Free Course β
![]() π Salesforce Administrators π Salesforce Lightning Flow Builder π Salesforce Record Trigger Flow Builder |
π Get Free Course β
![]() π Aura Lightning Framework π Lightning Web Component (LWC) π Rest APIs Integration |