1

I have one LWC component, which displays the list of Contacts. But its not displaying any data in the component. from debug log I can see my apex controller is returning data, but not sure why it is not getting displayed. I have taken the code from the lwc-recipes HTML:

<template>
    <lightning-card
        title="Apex Wire Method">
        <template if:true={contacts.data}>
            <template for:each={contacts.data} for:item="contact">
                <p key={contact.Id}>{contact.name}</p>
            </template>
        </template>
    </lightning-card>
</template>

js:

import { LightningElement, wire } from 'lwc';
import getContactList from '@salesforce/apex/ContactController.getContactList';

export default class ApexWireMetodToSalesforce extends LightningElement {
    @wire(getContactList) contacts;


}

Apex:

public with sharing class ContactController {

    @AuraEnabled(cacheable=true)
    public static List<Contact> getContactList() {
        return [SELECT Id, Name, Title, Phone, Email FROM Contact LIMIT 100];
    }

}
5
  • Could you please expose your apex controller? maybe you have missed querying name field?
    – Patlatus
    Mar 20 '19 at 11:29
  • are you sure you have saved and deployed every file (html, js, apex)?
    – Patlatus
    Mar 20 '19 at 11:30
  • also, can you add code `<template if:true={contacts.error}>{contacts.error}</template> to display any errors?
    – Patlatus
    Mar 20 '19 at 11:35
  • I have added apex controller in my question, yes every file is deployed in sfdc and I have added error condition but still its facing the issue Mar 20 '19 at 11:52
  • do you see any errors either in Javascript console, UI or Apex Logs? Could you please provide screenshot of what you are seeing and how do you detect that Apex is returning data? probably there are no contacts in your org
    – Patlatus
    Mar 20 '19 at 12:03
2

I was able to resolve, just by changing the name to Name in

<template for:each={contacts.data} for:item="contact">
                <p key={contact.Id}>{contact.name}</p>
            </template>

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.