I have an LWC that uses the wire below to query for an opportunity using an ID. Once I get the results, I'm struggling to assign the value of one of the fields returned by the wire to a variable. The returned value from apex is a list even though it will always return just one record.
here is LWC:
//wire to get opportunity info. Specifically the quotingdental field to display dental and bundled products
@wire(fetchOpp, {oppid: '$recordId'})
opps(data, error) {
if (data) {
console.log('$$ here is the data ' + JSON.stringify(data));
//This is the line I need help with.
this.quotingDental = this.data.Quoting_Dental__c;
//since we have data, update error to undefined
this.error = undefined;
}
else if (error) {
this.error = error;
this.quotingDental = undefined;
}
//needed to udpate data when there are no records to display - specificallly added when you delete the last record
else{
this.quotingDental = undefined;
this.error = undefined;
}
}
Here is what the returned data looks like:
$$ here is the data
{
"data": [
{
"Id": "006S000000MNxxxxx",
"Name": "Test1",
"OwnerId": "005S000000NYxxxxx",
"CloseDate": "2030-01-01",
"StageName": "Broker Prep",
"Quoting_Health__c": "No",
"Quoting_Dental__c": "Yes",
"Quoting_Vision__c": "No",
"Quoting_RX__c": "No",
"Quoting_Vol_Dental__c": "No",
"Quoting_Vol_Vision__c": "No",
"Quoting_Life_DI__c": "No",
"Owner": {
"Name": "frank",
"Id": "005S000000NYJxxxxx",
"CommunityNickname": "frank"
}
}
]
}