Apex アノテーション@AuraEnabledのサンプル
環境
Salesforce
説明
@AuraEnabled アノテーションにより、クライアント側およびサーバ側から
Apex コントローラメソッドへのアクセスが可能になります。
このアノテーションを指定することで、メソッドを Lightning コンポーネント
(Lightning Web コンポーネントと Aura コンポーネントの両方) で使用できるようになります。
使用箇所
Apexクラスの静的メソッド
Apex インスタンスのメソッドおよびプロパティ
使用例
public with sharing class TestAccountController {
@AuraEnabled
public static List<TestAccount> getAccounts() {
List<TestAccount> acAccounts = new List<TestAccount>();
List<Account> accounts = [SELECT Id, Name, Phone FROM Account LIMIT 10];
for (Account acct : accounts) {
acAccounts.add(new TestAccount(acct.Id, acct.Name, acct.Phone));
}
return acAccounts;
}
}