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
Yogesh Upadhyay 14Yogesh Upadhyay 14 

Lwc return value is [object Object]

Hi everyone can you please help me i am getting object object as return value.

 

js code :

import { LightningElement, wire, track } from 'lwc';
import mapDemo from '@salesforce/apex/Utility.mapDemo';
export default class LwcUtility extends LightningElement {
    @track name="Yogesh Upadhyay";
    @track message="Welcome";
    @track record;
    @track error;
    @track maps;
    @track conList= [
        {
            id:'12345678',
            name:'One two ka four',
            Phone:'100'
        },
        {
            id:'12345678',
            name:'One two ka five',
            Phone:'101'
        },
        {
            id:'12345678',
            name:'One two ka six',
            Phone:'102'
        }
    ];
    @wire(mapDemo)
     result({error,data}){
         if(data){
            this.record = data;
            console.log("return is "+this.record);
            JSON.stringify("hello",data);
         }
         if(error){
            this.error= error;
            console.log("retrun is "+this.error);
         }
     }
}

apex :
public with sharing class Utility {
    public Utility() {
    }
    @AuraEnabled 
    public static map<String,Integer> mapDemo(){
        map<String,Integer> testmap = new map<String,Integer>();
        testmap.put('avab',2);
        testmap.put('avab',2);
        testmap.put('avab',2);
        testmap.put('avab',2);
        return testmap;
    }
}
 

CloudGeekCloudGeek

Hello Yogesh,

Try this:

var accData = JSON.stringify(received_data);
var finalData = JSON.parse(accData);

CloudGeekCloudGeek

@Yogesh,

All wire requests have two attributes upon returning: data and error. so you have to use the .data attribute.
So - in your html file use it as  {ReturnValue.data}

Refer to this link: https://developer.salesforce.com/forums/?id=9062I000000XlRmQAK


Note: Mark it as answer if this resolves your issue.

ekansh parnamiekansh parnami
Try :
var data = JSON.stringify(received_data);
it will resolve your problem