以下のコードを参照してください。 Lightning Web コンポーネント JS ファイル JavaScript import {LightningElement} from 'lwc'; import serverEcho from '@salesforce/apex/SimpleServerSideController.serverEcho'; export default class Helloworld extends LightningElement { firstName = 'world'; handleClick() { serverEcho({ firstName: this.firstName }) .then((result) => { alert('From server: ' + result); }) .catch((error) => { console.error(error); }); } } Apex Controller Java public with sharing class SimpleServerSideController { @AuraEnabled public static String serverEcho(sObject firstName) { String firstNameStr = (String)firstName.get('firstName'); return ('Hello from the server, ' + firstNameStr); } } 上記のコードでは、コードを機能させるために Apex コントローラでどのような 2 つの変更を加える必要がありますか?
正解:B,C
The current Apex controller implementation contains a type mismatch between the data being sent from the JavaScript controller and the data type expected by the Apex method. In the JavaScript file, this.firstName is initialized as the string 'world'. When the serverEcho method is invoked, it passes this string value under the key firstName. In the Apex Controller, the parameter is incorrectly defined as an sObject. Because the JavaScript is passing a simple string, the Apex method signature must be updated to accept a String (Option B). Consequently, line 06-which attempts to use the .get() method (a method specific to sObjects)-is no longer valid and should be removed. Instead, the developer should directly use the firstName variable in the return statement (Option C). Option A is incorrect because @AuraEnabled is a method-level annotation, not a class-level one. Option D is incorrect because public static is the sufficient and standard access modifier for Apex methods exposed to Lightning components; global is only necessary if the component resides in a different namespace (such as in a managed package). By aligning the data types between the two layers, the serialization process can correctly map the JavaScript string to the Apex string variable.