Contents
Hands-on Challenge
Create an Apex class that returns Account objects.To pass this challenge, create an Apex class that returns a List of Account objects for a user-specified state.
- Create an Apex class named AccountUtils and include a static method named accountsByState that accepts a state abbreviation as a string and returns a List of Account objects
- The method must return the ID and name of all Account objects that match the BillingState for the state abbreviation passed to the method
日本語訳
アカウントオブジェクトを返すApexクラスを作成します。このチャレンジを渡すには、ユーザー指定の状態のアカウントオブジェクトのリストを返すApexクラスを作成します。
- 「AccountUtils」という名前のApexクラスを作成し、「accountsByState」という名前の静的メソッドを含めます。このメソッドは、州の略称を文字列として受け入れ、Accountオブジェクトのリストを返します
- メソッドは、メソッドに渡された州の略語のBillingStateに一致するすべてのAccountオブジェクトのIDと名前を返す必要があります
解答
今回はApexクラスの作成になります。
public class AccountUtils {
public static List<Account> accountsByState(String State){
return [
Select Id,Name
From Account
Where BillingState = :State
];
}
}
Listの初期化とかはめんどくさかったので、returnにそのままSOQLを貼り付けて返してます。

完了です。
コメント