CRT-450 Exam QuestionsBrowse all questions from this exam

CRT-450 Exam - Question 165


An Apex method, getAccounts, that returns a List of Accounts given a searchTerm, is available for Lightning Web components to use.

What is the correct definition of a Lightning Web component property that uses the getAccounts method?

A.

B.

C.

D.

Show Answer
Correct Answer:

The correct definition of a Lightning Web Component (LWC) property that uses an Apex method is by using the @wire decorator. The @wire decorator allows a property or function in an LWC to invoke an Apex method and receive the resulting data. Given this, option A is correct because it uses the @wire decorator correctly. It maps the searchTerm property from the LWC dynamically to the Apex method getAccounts using '$searchTerm', which is the proper syntax for passing dynamic data. The other options use @AuraEnabled, which is relevant for Aura components, not Lightning Web Components.

Discussion

7 comments
Sign in to comment
JCTheGenius
Aug 26, 2021

The code of C would be in the controller. In the lightning component it is the code related with the @wire property. The right syntax of it is A. Please refer to : https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.apex_wire_method

MuzaffarMoiz
Oct 11, 2021

Yes, Answer is A (@wire) property used in LWC component

KjlK
Nov 25, 2021

Answer A is Right @wire property

ApexMike
Oct 1, 2022

A is correct. You don't use Aura for LWC. You use wire

Keiyo
Sep 16, 2023

A import { LightningElement, wire } from 'lwc'; import getAccounts from '@salesforce/apex/YourApexClass.getAccounts'; export default class YourLWCComponent extends LightningElement { searchTerm = ''; // Initialize searchTerm property @wire(getAccounts, { searchTerm: '$searchTerm' }) accounts; // Rest of your component code... }

SanjeevOnForce
Nov 1, 2023

Its A if you are defining it in a LWC .js file

aregas
May 22, 2024

A - Lightning web components can import methods from Apex classes. The imported methods are functions that the component can call either via @wire or imperatively. https://developer.salesforce.com/docs/platform/lwc/guide/apex.html The @wire decorator tells getRecord to get the values of the specified fields on the record with the specified $recordId. The $ means that the value is passed dynamically. When the value changes, the wire service provisions data and the component rerenders. https://developer.salesforce.com/docs/platform/lwc/guide/data-wire-example.html