継続の @AuraEnabled アノテーション

継続では Apex コードで @AuraEnabled アノテーションを使用します。使い方のルールは次の通りです。

  • @AuraEnabled(continuation=true)

    継続を返す Apex コントローラメソッドには、@AuraEnabled(continuation=true) アノテーションを付加する必要があります。

  • @AuraEnabled(continuation=true cacheable=true)

    継続アクションの結果をキャッシュするには、Apex コールバックメソッドのアノテーションで cacheable=true と設定します。

    Note

continuation=true cacheable=true の間は、コンマではなくスペースで区切ってください。

:::

キャッシュの考慮事項 

Continuation オブジェクトを返すメソッドを含めて、継続チェーンに関与するすべてのメソッドで cacheable=true と設定するのがベストプラクティスです。

この例では、継続を返す Apex メソッド (startRequest()) とコールバック (processResponse()) の両方の @AuraEnabled アノテーションで cacheable=true が設定されています。

1// Action method
2@AuraEnabled(continuation=true cacheable=true)
3public static Object startRequest() { }
4
5// Callback method
6@AuraEnabled(cacheable=true)
7public static Object processResponse(List<String> labels,
8  Object state) { }

@AuraEnabled での cacheable 属性の各設定の動作を下表にまとめます。

cacheable=true のアノテーションが付いた、継続オブジェクトを返すメソッドcacheable=true のアノテーションが付いたコールバックメソッド有効かどうか@wire を使用してコール可能?アクションからの応答がクライアントでキャッシュされるかどうか
はいはいはいはいはい
はいいいえいいえ (例外をスロー)なしなし
いいえはいはいいいえ (すべてのメソッドで cacheable=true にする必要あり)いいえ
いいえいいえはいいいえいいえ

関連トピック

The Japanese Summer '24 guide is now live

日本語の Summer '24 ガイドが公開されました! 「Component Reference (コンポーネントリファレンス)」は、以前と同様にコンポーネントライブラリにあります。