RemoteActionを使い、
Apex側のメソッドをコールできる
しかし
JS側でコールする部分を別ファイル(静的リソース)に用意しロードすると
使える?
今回、この部分について
共有したいと思います
目次
SFDCのドキュメント:RemoteAction アノテーション
RemoteActionの使用
コントローラー側
global class YourControllerName { @RemoteAction global static String YourMethodName(Paramters....) { return 'Hello'; } }
VF側直接使用例
VF側
<apex:page controller="YourControllerName"> <script> Visualforce.remoting.Manager.invokeAction( '{!$RemoteAction.YourControllerName.YourMethodName}', [Parameters], function(result, event){ //処理内容 }); </script> </apex:page>
静的リソースでの使用例
静的リソースファイル:ResourceTest.js
YourControllerName.YourMethodName([Parameters],
function(result, event){
//処理内容
});
VF側で静的リソースファイルをコードする例
<apex:page controller="YourControllerName"> <apex:includeScript value="{!$Resource.ResourceTest}" /> </apex:page>