【Salesforce】Visualforce Remoting Exception: Unable to determine concrete type for Apex interface or abstract parameter ‘RemoteActionController.SuperClass’. Please provide ‘apexType’ value.
リモートアクションの呼出し時にエラーが発生しました。
1 |
Visualforce Remoting Exception: Unable to determine concrete type for Apex interface or abstract parameter 'RemoteActionController.SuperClass'. Please provide 'apexType' value. |
リモートアクションの引数が抽象クラスになってるけど、サブクラスがどれか分からないですよ、とのことです。
apexTypeを指定してね、とも書いてあります。
エラーが発生するのはこういうときです。
コントローラ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
public class RemoteActionController{ /** * VFから呼び出すリモートアクション * @param なし * @return SuperClassのインスタンス */ @RemoteAction public static SuperClass getClassInstance(){ return new SubClassA(); } /** * VFから呼び出すリモートアクション * @param param 親クラスのサブクラス * @return なし */ @RemoteAction public static void remoteActionMethod(SuperClass param){} /** * 内部クラス(親) */ public abstract class SuperClass {} /** * 内部クラス(子) */ public class SubClassA extends SuperClass {} /** * 内部クラス(子) */ public class SubClassB extends SuperClass {} } |
Visualforce
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<script> // 画面読み込み後にJavaScriptを呼び出す document.addEventListener('DOMContentLoaded', function(){ // インスタンスを取得する {!$RemoteAction.RemoteActionController.getClassInstance}(afterCreateImportManagerInstance); }); // インスタンス作成処理のコールバック処理 function afterCreateImportManagerInstance(result, event){ let instance; // 戻り値のインスタンスを取得する instance = result; // インスタンスを引数に持つメソッドを呼び出す // エラー {!$RemoteAction.RemoteActionController.remoteActionMethod}(instance, afterRemoteActionMethod); } // インスタンスを引数に持つメソッド呼出し後の処理 function afterRemoteActionMethod(result, event){} </script> |
たしかに、どちらのサブクラスを使えば良いか分かりません。
エラーで記述されているように、apexTypeを設定してやります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
public class RemoteActionController { /** * VFから呼び出すリモートアクション * @param なし * @return SuperClassのインスタンス */ @RemoteAction public static SuperClass getClassInstance(){ return new SubClassA(); } /** * VFから呼び出すリモートアクション * @param param 親クラスのサブクラス * @return なし */ @RemoteAction public static void remoteActionMethod(SuperClass param){ } /** * 内部クラス(親) */ public abstract class SuperClass { protected String apexType; /** * コンストラクタでapexTypeに値を設定する */ public SuperClass(){ this.apexType = this.getApexType(); } /** * サブクラスでApexTypeを取得するメソッドを実装させる */ protected abstract String getApexType(); } /** * 内部クラス(子) */ public class SubClassA extends SuperClass { protected override String getApexType(){ return 'c.RemoteActionController.SubClassA'; } } /** * 内部クラス(子) */ public class SubClassB extends SuperClass { protected override String getApexType(){ return 'c.RemoteActionController.SubClassA'; } } } |
基底クラスのコンストラクタでapexTypeに値を設定する処理を追加しました。
さらに、抽象メソッドで子クラスにapexTypeを返すようにしてあります。
apexTypeに設定する値は、フルネームなんだそうです。
この組織の中で作成しているため、「c.」が頭につくわけですね。
これで問題は解決しました。
No comments.