+ Start a Discussion
JeffreyStevensJeffreyStevens 

lwc apex call returns [object Object]

So, I have a lightning web component that calls an APEX method to return something.  When I try to display what the APEX returns, I always get [object Object] in the html.

Here's the code:
//.js....
import { LightningElement, api, wire } from 'lwc';
import acceptRtnSomthing from '@salesforce/apex/HelperAccount.acceptRtnSomthing';

export default class UltimateParentMRR extends LightningElement {
    @api recordId;
    somethingReturned = "Value in .js....";
    
    @wire(acceptRtnSomthing, {recId : '$recordId' })
        somethingReturned;

}




// HTML....
<template>
    <lightning-card title="Ultimate Parent MRR" icon-name="standard:account">
        <div class="slds-m-around_medium">
            {somethingReturned}
        </div>
    </lightning-card>
</template>


// APEX...
@AuraEnabled (cacheable=true)
	public static string acceptRtnSomthing(string recId){
		return recId;
	}
If I comment out the call to the APEX - I get "Value in .js...." in the HTML output.

Does anybody see my issue?

Thanks!
 
Best Answer chosen by JeffreyStevens
lnallurilnalluri
@Jeffrey

Can you try after decorating somethingReturned with track or api? also in your html file replace {somethingReturned} with {somethingReturned.data}

Thanks.



 

All Answers

JeffreyStevensJeffreyStevens
Here is the output...
Image of HTML output where it just shows [object Object]
JeffreyStevensJeffreyStevens
Found the answer.

All wire requests have two attributes upon returning: data and error. I needed to use the .data attribute.

So - {somethingReturned.data}
lnallurilnalluri
@Jeffrey

Can you try after decorating somethingReturned with track or api? also in your html file replace {somethingReturned} with {somethingReturned.data}

Thanks.



 
This was selected as the best answer