I need to pass data from LWC to Apexclass, But in apexlass i am getting it as null, But in LWC console i am getting values. Please help me where i did the wrong.
LWC:
import { LightningElement, api, wire, track } from 'lwc';
import { getRecord, getObjectInfo, getPicklistValues, getFieldValue, updateRecord } from 'lightning/uiRecordApi';
import getallMetadata from '@salesforce/apex/RegionController.getallMetadata';
import getmdata from '@salesforce/apex/RegionController.getRegion';
import createUpdateMetadata from '@salesforce/apex/RegionController.createUpdateMetadata'; // to save record.
import picklistval from '@salesforce/apex/RegionController.getallMetadatapiclist';
export default class Custmetadata extends LightningElement {
@track myMap = [];
@track meatadataLabel;
handleClick(event) {
console.log('Inside Button click ' + event.detail.name);
this.editmode = true;
this.displaydetails = false;
const label = event.target.label;
if (label === 'Update') { }
else if (label === 'Save') {
let i;
let fieldMap;
let checkboxes = this.template.querySelectorAll('[data-id="checkbox"]')
for (i = 0; i < checkboxes.length; i++) {
this.fieldMap = [...checkboxes].reduce((p, v) => (p[v.name] = p.checked, p), {});
}
console.log('myMap data === ' + this.fieldMap);
console.log('myMap data === ' + JSON.stringify(this.fieldMap));
createUpdateMetadata({ fullName: this.metadataname, label: this.value, fieldWithValuesMap: this.fieldMap }) //
.then(result => {
var options = [];
if (result) {
console.log(result);
}
})
.catch(error => {
console.log(error);
});
}
}
Apex class:
@AuraEnabled(cacheable=true)
public static void createUpdateMetadata(String fullName, String label, Map<String, Object> fieldWithValuesMap){ //
Metadata.CustomMetadata customMetadata = new Metadata.CustomMetadata();
system.debug('fieldWithValuesMap --'+fieldWithValuesMap);
customMetadata.fullName = fullName;
customMetadata.label = label;
for(String key : fieldWithValuesMap.keySet()){
Metadata.CustomMetadataValue customField = new Metadata.CustomMetadataValue();
customField.field = key;
customField.value = fieldWithValuesMap.get(key);
customMetadata.values.add(customField);
}
Metadata.DeployContainer mdContainer = new Metadata.DeployContainer();
mdContainer.addMetadata(customMetadata);
}
Output in LWC console:
Prepared map result --- >[{"key":"test","value":true},{"key":"test2","value":true},{"key":"trest3","value":false},{"key":"test4","value":true},{"key":"test233","value":false}]
this.myMap --- [object Object],[object Object],[object Object],[object Object],[object Object]