Plat-Dev-301 practice question 6 of 10
Refer to the code below: Lightning Web Component JS file JavaScript import {LightningElement} from 'lwc'; import serverEcho from…
Full set: 160 questionsThe Lightning Web Component passes a JavaScript object { firstName: 'someValue' } to the Apex method. The Apex method signature must correctly map to this structure.
1. The parameter type should be String, and the parameter name must match the key in the JavaScript object (firstName). Therefore, the signature must be changed from serverEcho(sObject firstName) to serverEcho(String firstName).
2. With the corrected signature, the firstName parameter directly holds the string value. The line String firstNameStr = (String)firstName.get('firstName'); is now incorrect and unnecessary, as a String variable has no .get() method. This line must be removed, and the firstName parameter should be used directly in the return statement.
A. Annotating the entire class with @AuraEnabled is a valid alternative to annotating each method, but it is not a required change for the existing code to work.
D. The public access modifier is sufficient for a method to be called from a Lightning component in the same namespace. global is not required.
1. Salesforce Developers Documentation, Lightning Web Components Dev Guide, "Call Apex Methods", Section: "Pass Parameters to Apex Methods". This guide shows that when passing a JavaScript object, the properties map to the named parameters in the Apex method.
2. Salesforce Developers Documentation, Apex Developer Guide, "AuraEnabled Annotation", Section: "Using the @AuraEnabled Annotation". This documentation confirms that @AuraEnabled can be used on static methods and that public or global access modifiers are required. It does not mandate global.
3. Salesforce Developers Documentation, Apex Developer Guide, "Data Types". This reference details the methods available for primitive types like String, confirming it does not have a .get() method, unlike sObject.
Keep practicing
Take the free Plat-Dev-301 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other Plat-Dev-301 practice questions
- Question 1Which use case can be performed only by using asynchronous Apex?
- Question 2The Account object has a field, Audit_Code__c, that is used to specify what type of audit…
- Question 3How should a developer verify that a specific Account record is being tested in a test cl…
- Question 4There is an Apex controller and a Visualforce page in an org that displays records with a…
- Question 5A developer created and tested a Visualforce page in their developer sandbox, but now rec…
- Question 7A developer is developing a reusable Aura component that will reside on an sObject Lightn…
