How to Fetch/Edit Custom Metadata Type Records Uses of lightning:datatable and onrowaction operation in Lightning Component Salesforce | how to custom metadata retrieve/edit through apex in aura lighting component Salesforce

1,462 views


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

Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
   

custom metadata record type retrieve edit through apex salesforce -- w3web.net

 

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]

  1.    <aura:component controller="customMetadataCtrl" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >    
  2.     <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>    
  3.     <aura:attribute name="metaList" type="customMetadataIntegrate__mdt[]"/>
  4.     <aura:attribute name="data" type="Object"/>
  5.     <aura:attribute name="columns" type="List"/> 
  6.  
  7.     <aura:attribute name="record" type="Object"/>
  8.  
  9.  
  10.     <div class="slds slds-p-around--medium">
  11.  
  12.         <lightning:card variant="Narrow" title="Metadata Action Row" iconName="custom:custom66">
  13.  
  14.             <lightning:datatable columns="{! v.columns }"
  15.                                  data="{! v.data }"
  16.                                  keyField="id"
  17.                                  onrowaction="{! c.metaActionRow}"
  18.                                  hideCheckboxColumn="true"/>
  19.         </lightning:card>  
  20.  
  21.  
  22.  
  23.         <div class="slds-hide" aura:id="metaRowPopupId" style="height: 340px; ">
  24.             <section class="slds-modal slds-fade-in-open">
  25.                 <div class="slds-modal__container">
  26.                     <header class="slds-modal__header">
  27.                         <button class="slds-button slds-button_icon slds-modal__close slds-button_icon-inverse" onclick="{!c.handleCancelPopupClick }" title="Close">
  28.                             <lightning:icon iconName="utility:close" alternativeText="Approved" />
  29.                         </button>
  30.                         <h2 class="slds-text-heading_medium slds-hyphenate">Metadata Action Row</h2>
  31.                     </header>
  32.                     <div class="slds-modal__content slds-p-around_medium">
  33.                         <div class="slds-form slds-form_stacked">
  34.                             <div class="slds-form-element">
  35.                                 <lightning:input type="text" name="MasterLabel" label="MasterLabel" value="{!v.record.MasterLabel}"/>
  36.                             </div>
  37.                             <div class="slds-form-element">
  38.                                 <lightning:input type="text" name="ApiEndpoint" label="Api Endpoint" value="{!v.record.Api_Endpoint__c}"/>
  39.                             </div>  
  40.                             <div class="slds-form-element__control" >
  41.                                 <lightning:input type="text" label="Bucket" name="Bucket" value="{!v.record.Bucket__c}"/>
  42.                             </div>
  43.                             <div class="slds-form-element__control" >
  44.                                 <lightning:input type="text" label="Call Back URL" name="CallBackURL" value="{!v.record.Call_Back_URL__c}"/>
  45.                             </div>
  46.                             <div class="slds-form-element__control" >
  47.                                 <lightning:input type="text" label="Active" name="Active" value="{!v.record.Active__c}"/>
  48.                             </div>
  49.                         </div>
  50.                     </div>
  51.                     <footer class="slds-modal__footer">
  52.                         <lightning:button class="slds-button slds-button_destructive" label="Cancel" title="Cancel" onclick="{! c.handleCancelPopupClick }"/>
  53.                     </footer>
  54.                 </div>
  55.             </section>
  56.             <div class="slds-backdrop slds-backdrop_open"></div>
  57.         </div>
  58.         <br/>
  59.    <!--Start RelatedTopics Section-->
  60. <div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
  61.  
  62.             <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>
  63.  
  64.             <br/><br/>
  65.             <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>
  66.             <div style="display:block; overflow:hidden;"> 
  67.                 <div style="width: 50%; float:left; display:inline-block">
  68.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  69.                         <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>
  70.                         <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>
  71.                         <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>
  72.                         <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>
  73.                         <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>
  74.                     </ul>
  75.             </div>
  76.  
  77.             <div style="width: 50%; float:left; display:inline-block">
  78.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  79.                         <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>
  80.                         <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>
  81.                         <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>
  82.                         <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>
  83.                         <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>
  84.                     </ul>
  85.                 </div>
  86.                <div style="clear:both;"></div> 
  87.                <br/>
  88.                 <div class="youtubeIcon">
  89.                     <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>
  90.                 </div>
  91.     </div>
  92.  
  93. </div>
  94.  
  95.   <!--End RelatedTopics Section-->
  96.     </div>
  97. </aura:component>

Create JavaScript Controller

Step 2:- Create Lightning Component : customMetadataCmpController.js

Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
   

From Developer Console >> File >> New >> Lightning Component >> JavaScript Controller

customMetadataCmpController.js [JavaScript Controller]

  1.    ({
  2. 	doInit : function(component, event, helper) {
  3.         helper.initHelper(component, event, helper);
  4. 	},
  5.  
  6.  
  7.     metaActionRow: function ( component, event, helper ) {
  8.         var action = event.getParam('action');
  9.         var row = event.getParam('row');
  10.         //alert('row ' + JSON.stringify(row));
  11.         switch (action.name) {
  12.             case 'edit_record':
  13.                 component.set( "v.record", row );
  14.                 var metaEle = component.find( "metaRowPopupId" );
  15.         		$A.util.removeClass( metaEle, "slds-hide" );
  16.                 break;
  17.         }
  18.     },
  19.     handleCancelPopupClick: function( component, event, helper ){        
  20.         var metaEle = component.find( "metaRowPopupId" );
  21.         $A.util.addClass( metaEle, "slds-hide" );
  22.     },
  23.  
  24.  
  25. })

Create JavaScript Helper

Step 3:- Create Lightning Component : customMetadataCmpHelper.js

From Developer Console >> File >> New >> Lightning Component >> JavaScript Helper

customMetadataCmpHelper.js [JavaScript Helper File]

  1.    ({
  2. 	initHelper : function(component, event, helper) {       
  3.         let rowActions = [{ 
  4.             'label': 'Edit', 
  5.             'iconName': 'action:edit', 
  6.             'name': 'edit_record' 
  7.         }]; 
  8.  
  9.         let columns = [                     
  10.             { label: 'MasterLabel', fieldName: 'MasterLabel', type: 'text' }, 
  11.             { label: 'Api Endpoint', fieldName: 'Api_Endpoint__c', type: 'url' },
  12.             { label: 'Bucket', fieldName: 'Bucket__c', type: 'text'},
  13.             { label: 'Call Back URL', fieldName: 'Call_Back_URL__c', type: 'url'},            
  14.             { label: 'Active', fieldName: 'Active__c', type: 'text'},
  15.             { type: 'action', typeAttributes: { rowActions: rowActions } }
  16.         ];	
  17.  
  18.         component.set( "v.columns", columns );
  19.  
  20.         helper.retrieveDataHelper( component );
  21.  
  22.     },
  23.  
  24.     retrieveDataHelper : function( component ) {
  25. 		var action = component.get("c.customMetaObj");
  26.         action.setCallback( this, function( response ) {
  27.             var state = response.getState();
  28.             if( state === "SUCCESS") {
  29.                 var result = response.getReturnValue();
  30.                 //alert('result' + JSON.stringify(result));
  31.                 //console.log( response.getReturnValue() );
  32.                 component.set( "v.data", result );
  33.             }
  34.             else if (state === "INCOMPLETE") {
  35.             	alert('Error in the response');
  36.             }
  37.             else if (state === "ERROR") {
  38.                 var errors = response.getError();
  39.                 if (errors) {
  40.                     if (errors[0] && errors[0].message) {
  41.                         console.log("Error message: " + 
  42.                                  errors[0].message);
  43.                     }
  44.                 } else {
  45.                     console.log("Unknown error");
  46.                 }
  47.             }
  48.         });
  49.  
  50.         $A.enqueueAction( action );
  51.     },
  52.  
  53.  
  54.  
  55. })

Create Apex Class Controller

Step 4:- Create Apex Class : customMetadataCtrl.apxc

From Developer Console >> File >> New >> Apex Class

customMetadataCtrl.apxc [Apex Class Controller]

  1.     public class customMetadataCtrl {
  2.  
  3.   @AuraEnabled
  4.     public static List<customMetadataIntegrate__mdt> customMetaObj(){
  5.         List<customMetadataIntegrate__mdt> metaObj = [SELECT Id, MasterLabel, Api_Endpoint__c, Bucket__c, Call_Back_URL__c, Folder__c, Active__c FROM customMetadataIntegrate__mdt];
  6.         system.debug('metaObj#__11 ' + metaObj);
  7.         RETURN metaObj;
  8.     }
  9.  
  10.  
  11. }

Create Lightning Application

Step 5:- Create Lightning Application : customMetadataApp.app

From Developer Console >> File >> New >> Lightning Application

customMetadataApp.app [Component Application File]

  1.    <aura:application extends="force:slds">
  2.     <c:customMetadataCmp/>
  3. </aura:application>

custom metadata record type retrieve edit through apex salesforce -- w3web.net

Further post that would you like to learn in Salesforce

 

 

FAQ (Frequently Asked Questions)

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

 
Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
 
 
  

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



Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

Leave a Comment