public with sharing class CustomMetadataController {
@AuraEnabled
public static String getCustomMetadata() {
List<CustomMetadatamdt> metadataList = [SELECT Id, Name, Headerc, Typec FROM CustomMetadatamdt];
List<Map<String, String>> result = new List<Map<String, String>>();
for (CustomMetadata__mdt metadata : metadataList) {
Map<String, String> item = new Map<String, String>();
item.put('Header', metadata.Header__c);
item.put('Type', metadata.Type__c);
result.add(item);
}
return JSON.serialize(result);
}
}
import { LightningElement, wire } from 'lwc';
import getCustomMetadata from '@salesforce/apex/CustomMetadataController.getCustomMetadata';
export default class CustomMetadataComponent extends LightningElement {
metadata = [];
connectedCallback() {
this.loadMetadata();
}
loadMetadata() {
getCustomMetadata()
.then((result) => {
this.metadata = JSON.parse(result);
this.processMetadata(this.metadata);
})
.catch((error) => {
console.error('Error fetching metadata:', error);
});
}
processMetadata(metadata) {
// 여기서 metadata를 처리합니다
metadata.forEach(item => {
console.log('Header:', item.Header);
console.log('Type:', item.Type);
});
}
}