Skip to main content

I'm running into issues with this challenge: https://trailhead.salesforce.com/content/learn/modules/lightning-web-components-and-salesforce-data/use-apex-to-work-with-data?trail_id=force_com_dev_intermediate

 

As far as I can tell, I have replaced all the "Account" references from the example with "Contact", but I still can't compile the code in Visual Studio. I get the following errors:

 

ContactController.cls

* Illegal conversion from List<Contact> to List<Account> (4:9)

public with sharing class ContactController {

@AuraEnabled(cacheable=true)

public static List<Contact> getContacts() {

return [

SELECT FirstName, LastName, Email

FROM Contact

WITH SECURITY_ENFORCED

ORDER BY LastName

];

}

}

contactList.js

* Unable to find Apex action class referenced as 'ContactController'.

* LWC1535: Unexpected plugin compilation error: Plugin - lwc, Hook - transform, Cause - SyntaxError: /home/sfdc/tools/lwc/244.20.1-2.41.4/contactList.js: LWC1119: Failed to resolve @wire adapter "getContacts". Ensure it is imported. (21:8)

 

import { LightningElement, wire } from 'lwc';

import FIRST_NAME_FIELD from '@salesforce/schema/Contact.FirstName';

import LAST_NAME_FIELD from '@salesforce/schema/Contact.LastName';

import EMAIL_FIELD from '@salesforce/schema/Contact.Email';

import getContacts from '@salesforce/apex/ContactController.getContacts';

const COLUMNS = [

{ label: 'First Name', fieldName: FIRST_NAME_FIELD.fieldApiName, type: 'text' },

{ label: 'Last Name', fieldName: LAST_NAME_FIELD.fieldApiName, type: 'text' },

{ label: 'Email', fieldName: EMAIL_FIELD.fieldApiName, type: 'text' }

];

export default class ContactList extends LightningElement {

columns = COLUMNS;

@wire(getContacts)

contacts;

}

4 Antworten
  1. 29. Juni 2023, 23:31

    I think that I figured this out. The ContactController.cls-meta.xml was interfering with the class somehow. When I deleted this, it ended up being ok. 

    I think that I figured this out. The ContactController.cls-meta.xml was interfering with the class somehow. When I deleted this, it ended up being ok.

0/9000