function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Laurie DrewLaurie Drew 

Hi need help displaying filtered data in LWC only once

Hello All, 
I am working on an LWC that ultimately should display 1 field from  custom metadata records (Call Script Layout) that I created.  In the process of figuring everything out.  In my apex controller I query to build a map<String, Object>, key is MasterLabel, then all the fields in the mdt object.  I get it pulled into my lwc successfully and filtered down to the 1 record that I was to display 1 time.  Issue I have is it is being displayed 214 times (this is the # of metadata records there are total).  While working through this I was filtering in the HTML, but when I attempt to remove the for:each and display just the one record, it breaks.  I've tried changing the variables in map to Map<String,String> but get error that the field in the second string cannot be found. 

My Apex Controller:

@AuraEnabled(cacheable=true)
public static Map<String, SObject> fetchQuestionMap() {
Map<String, Call_Script_Layout__mdt> questionMap = new Map<String, Call_Script_Layout__mdt>();
for(Call_Script_Layout__mdt csl : [SELECT Id, MasterLabel, Section__c, Question__c, Order__c FROM Call_Script_Layout__mdt ORDER BY Section__c])
questionMap.put(csl.MasterLabel, csl);
return questionMap;
}

LWC: I am calling multiple child LWC's that are not in this code:

HTML:
<template>
<template for:each={mapData} for:item="mapKey">
<c-call-script-_-coverage key = {mapKey.key} question = {mapKey.value}></c-call-script-_-coverage>
</template>
</template>

JS:

import { LightningElement, api, wire, track} from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
import fetchQuestionMap from '@salesforce/apex/callScript_CustomMetadataController.fetchQuestionMap';
const FIELDS = [
'Lead.Name',
];
export default class CallScript_FetchQuestion extends LightningElement {
@api
recordId;
@wire(getRecord, { recordId: '$recordId', fields: FIELDS })
lead;
@track mapData = [];
// Filter down to be a single question
@wire(fetchQuestionMap) wiredResult(result){
if (result.data) {
var conts = result.data;
for(var key in conts){
if(key ='CoverageType'){
this.mapData.push({value:conts[key], key:key});
}
}
}
}
}

meta file:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>55.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
<target>lightning__HomePage</target>
</targets>
</LightningComponentBundle>

I would really appreciate it if someone can tell me how I can get just 1 instance of the metadata record to display?
 
Laurie DrewLaurie Drew
Here is the child lwc:

<template>
<p key={question.Id}>
{question.Question__c}
</p>
</template>

import { LightningElement, api } from 'lwc';
export default class callScript_Coverage extends LightningElement {
@api question;
}