You need to sign in to do that
Don't have an account?
Konark saini 11
How to get custom metadata record field values?
I have developed a class in which i am retrieving custom metadata record and dispalying it on a lwc component.
But i also want to get values of each field corresponding to that record and store in variable in my lwc js file.
How can i achieve this?
But i also want to get values of each field corresponding to that record and store in variable in my lwc js file.
How can i achieve this?
Refer the below link will help you to proceed further.
https://www.infallibletechie.com/2021/03/how-to-fetch-and-display-custom.html
Thanks!!
I am not able to resolve the issue by going through the link given.
I am attaching the code for controller and the js for your better understanding.
Please guide me for the same.
Use Case: I want to get only the name value from the displayed data.
getMetadataRecords.cls
public with sharing class getMetadataRecords {
@AuraEnabled(cacheable=true)
public static List<Employee_Details__mdt> getRecords(String employeeId) {
String selectedEmp;
List<Employee_Details__mdt> mcs = [SELECT Employee_Id__c,Employee_Name__c,Employee_Email__c,Employee_Number__c FROM Employee_Details__mdt];
for(Employee_Details__mdt records: mcs){
if(records.Employee_Id__c==employeeId){
selectedEmp =records.Employee_Id__c;
}
}
List<Employee_Details__mdt> mcs1= [SELECT Employee_Id__c,Employee_Name__c,Employee_Email__c,Employee_Number__c FROM Employee_Details__mdt WHERE Employee_Id__c = : selectedEmp];
return mcs1;
}
}
childSalary.js
import { LightningElement ,wire,api} from 'lwc';
import getEmployeeData from '@salesforce/apex/getMetadataRecords.getRecords';
const COLUMNS = [
{label: 'Employee Id', fieldName: 'Employee_Id__c' ,sortable: 'true'},
{ label: 'Employee Name', fieldName: 'Employee_Name__c',sortable: 'true' },
{ label: 'Phone', fieldName: 'Employee_Number__c',sortable: 'true' }
];
export default class ChildSalary extends LightningElement {
@api strOutput
records;
error;
columns = COLUMNS;
firedOnce=true;
workingDays=false;
@wire( getEmployeeData ,{employeeId :'$strOutput'})
wiredRecords( { error , data } ) {
if ( data ) {
this.records = data;
this.error = undefined;
} else if ( error ) {
this.error = error;
this.records = undefined;
}
}
enterWorkingDays(){
this.workingDays=true;
}
}
childSalary.html
<template>
<lightning-card>
<lightning-datatable
if:true={firedOnce}
key-field="Id"
data={records}
columns={columns}
hide-checkbox-column="false">
</lightning-datatable>
<br>
<lightning-button variant="Brand" label="Next" class="slds-m-horizontal_xxx-small" onclick={enterWorkingDays}></lightning-button>
<template if:true={workingDays}>
<c-working-day></c-working-day>
</template>
</lightning-card>
</template>
Please guide me!!