マイオポチュニティ.js JavaScript import { LightningElement, api, wire } from 'lwc'; import getOpportunities from '@salesforce/apex/OpportunityController.findMyOpportunities'; export default class MyOpportunities extends LightningElement { @api userId; @wire(getOpportunities, {oppOwner: '$userId'}) opportunities; } OpportunityController.cls Java public with sharing class OpportunityController { @AuraEnabled public static List<Opportunity> findMyOpportunities(Id oppOwner) { return [ SELECT Id, Name, StageName, Amount FROM Opportunity WHERE OwnerId = :oppOwner ]; } } 開発者がLightning Webコンポーネントで問題を抱えています。このコンポーネントは、現在ログインしているユーザーが所有する商談に関する情報を表示する必要があります。コンポーネントをレンダリングすると、「データ取得エラー」というメッセージが表示されます。これを接続可能にするには、Apexメソッドでどのアクションを実行する必要がありますか?
正解:C
To use the @wire service in a Lightning Web Component (LWC) to retrieve data from an Apex method, the Apex method must be marked as cacheable. In the provided OpportunityController class, the findMyOpportunities method is annotated with @AuraEnabled, but it lacks the mandatory cacheable=true property. The @wire service is part of the Lightning Data Service (LDS) reactive framework. Salesforce requires wireable methods to be cacheable to improve performance and ensure that data can be stored in the client-side cache. Without (cacheable=true), the @wire decorator will fail to execute, resulting in the "Error retrieving data" message or a similar runtime failure. Option C is the correct fix: the developer must update the annotation to @AuraEnabled(cacheable=true). Option A (Continuation) is only for long-running external callouts. Option B (without sharing) might affect visibility but isn't a requirement for the wire service itself. Option D (OWD) affects whether records are visible based on security, but the technical failure described is rooted in the component-to-Apex binding requirement. Once marked as cacheable, the LDS can properly manage the data lifecycle for the component.