0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Salesforce】PageReference メソッド / getContent()は非同期では使えない?

Posted at

問題

PageReference メソッド/getContent()

getContent()は非同期処理では使用不可?

@futureメソッドにてgetContent()メソッドを使用した場合、「 @future call currently not allowed 」エラーが表示。

解決策

@future call currently not allowed 」のエラーは、Visualforce ページのコンストラクタにおいて @future の非同期処理を開始しようとした際に発生するエラー。

  • カスタムコントローラおよびコントローラ拡張の作成に関する考慮事項

コントローラ、またはコントローラのコンストラクタでは、「getxxx」または「setxxx」メソッドに @future アノテーションを使用することはできません。

回避策
コンストラクタでの処理ではなく、apex:page の action 属性にて @future の処理を実行することが候補。

  • apex:page | Visualforce 開発者ガイド

なお、getContent() をご利用いただく際には他にも留意事項あり。
getContent() のメソッドはコールアウトの処理。

  • getContent() | Apex 開発者ガイド

API バージョン 34.0 以降では、getContent はコールアウトとして扱われます。

コールアウトには制限事項があり、insert 等の DML ステートメントの後には実行不可。

  • コールアウトの制限事項 | Apex 開発者ガイド

同じトランザクション内に待機中の操作が存在する場合はコールアウトを実行できません。操作が待機中となるものには、DML ステートメント、非同期 Apex (future メソッドや Apex 一括処理ジョブなど)、スケジュール済み Apex、メールの送信があります。このような操作を行う前に、コールアウトを実行するようにします。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?