0
<template>
    <lightning-card title="AllContacts">
        <ul>
            <template if:true={responseReceived}>

                <template for:each={contacts.data} for:item="contact">
                <p key={contact.id}>
                        {contact.lastname}
                </p>
                </template>
            </template>
            <template if:false={msg}></template>
        </ul>
    </lightning-card>
</template>

JS

import { LightningElement,wire,track } from 'lwc';
import getAllContacts from '@salesforce/apex/Message.getInpMessage'
export default class AccountManagerApex extends LightningElement {
@track contacts;
    @wire(getAllContacts) 
    contacts;
    msg="error";
    get responseReceived(){
        if(this.accounts){
            return true;
        }
        return false;
    }

}

Apex:

public with sharing class Message {
    @AuraEnabled(cacheable=true)
    public static List<contact> getInpMessage() {
        return [select id,lastname from contact];
    }
}
1

You are binding wire to contacts variable, but you are checking this.accounts in responseReceived

Alter you responseReceived method

get responseReceived(){
        if(this.contacts){
            return true;
        }
        return false;
    }

Also LWC is case sensitive. Thus Id and Lastname should have proper case

<p key={contact.Id}>
     {contact.Lastname}
</p>
| improve this answer | |
  • I was going to answer this .. hehe :D btw yea this may be the solution. :) – Sahil Malhotra May 12 at 9:28
  • get responseReceived(){ return !!this.contacts; } would be the standard way of doing this check in JavaScript. – sfdcfox May 12 at 13:26

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.