2

I'm trying to put debug log in LWC but getting this error

enter image description here

Even after adding

/* eslint-disable no-console */
// eslint-disable-next-line no-console

and

"rules": {
    "no-console": "off",
    "no-alert": "off"
}

Bascially I haved added everything mentioned in this answer

JS:

import { LightningElement,api,wire } from 'lwc';
import getValue from '@salesforce/apex/ScController.getValue';

export default class ScScoreCard extends LightningElement {
    @api recordId;
    @wire(getValue, {opportunityId: '$recordId'}) valueList;

    // eslint-disable-next-line no-console
    console.log(">>> valueList... "+valueList);
    }
  • can you add the whole code snippet? – Pranay Jaiswal Apr 3 at 13:22
  • @salesforce Developer, as a side note, why arent you adding a debugger statement in your code, instead of console logs ? – glls Apr 3 at 13:27
10

You need to put "executable statements" inside a function. For example, if you wanted to call it during construction:

import { LightningElement,api,wire } from 'lwc';
import getValue from '@salesforce/apex/ScController.getValue';

export default class ScScoreCard extends LightningElement {
    @api recordId;
    @wire(getValue, {opportunityId: '$recordId'}) valueList;

    constructor() {
        super(); // Must be called first
        console.log(">>> valueList... "+valueList);
    }
}

Of course, this won't actually work, since the data won't be there yet. You need to write a function to handle the results:

import { LightningElement,api,wire } from 'lwc';
import getValue from '@salesforce/apex/ScController.getValue';

export default class ScScoreCard extends LightningElement {
    @api recordId;
    @track results;
    @wire(getValue, {opportunityId: '$recordId'}) 
    valueList({ error, data }) {
        console.log(data);
        this.results = data;
        this.error = error;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.