Plat-Dev-201 practice question 12 of 30

Which code statement includes an Apex method named updateAccounts in the class AccountController for use in a Lightning web component?

Full set: 204 questions
Answer options
A: import updateAccounts from "AccountControlles';
B: import updateAccounts from "Salesforce/apex/AccountController:';
C: import updateAccounts from "[email protected]';
D: import updateAccounts from "@salesforce/apex/AccountController.updateAccounts"; Correct answer
Correct Answer:
D. import updateAccounts from "@salesforce/apex/AccountController.updateAccounts";
Explanation

To call an Apex method from a Lightning Web Component (LWC), the method must be imported into the component's JavaScript file. The correct syntax for this import statement is import methodName from '@salesforce/apex/ClassName.methodName'. This syntax tells the LWC framework to make the specified @AuraEnabled Apex method available for the component to call. The @salesforce/apex scoped module provides the mechanism to communicate with the Apex controller from the client-side JavaScript.

Why Incorrect

A. This syntax is incorrect. It lacks the required @salesforce/apex scoped module and the specific method name, and contains a typo in the class name.
B. This syntax is incorrect. It uses Salesforce/apex/ instead of the required @salesforce/apex scoped module and a colon instead of a period.
C. This syntax is incorrect. It is missing the @salesforce/apex scoped module which is necessary to identify the import as an Apex method.

References

- Salesforce Lightning Web Components Dev Guide, "Call Apex Methods", Section: "Import an Apex Method". The guide explicitly shows the syntax: import apexMethodName from '@salesforce/apex/Namespace.ClassName.apexMethodName';.

- Salesforce Apex Developer Guide, "Calling Apex from Lightning Web Components", Section: "Calling an Apex Method". This section reinforces the import syntax and the requirement for the Apex method to be static and @AuraEnabled.

Scroll to Top