課題の前のカリキュラムで実施している内容は、事前に全部終わっている状態で実施してます。
※やらないでも達成できるかは試してません。
Create a Relationship Query
Use SOQL to identify properties listed with DreamHouse Realty in the last 30 days.
If you didn’t already install the DreamHouse package and import sample data, follow the instructions at the beginning of this unit to do that now.
https://trailhead.salesforce.com/ja/content/learn/modules/soql-for-admins/create-relationship-queries-with-custom-objects?trail_id=build-apex-coding-skills
- Create a class
- Name:
PropertyUtility
- Create a method
- Name:
newListedProperties
- Keywords:
public, static
, andvoid
- Create a list
- Name:
newPropList
- Create a query and assign the query results to the list
- Get this information:
(Hint: Use API names, not field names or field labels)
- The name of the property
- The broker’s email address
- How long the property has been on market
- Object: Property
- Condition: The property was listed within the last 30 days
- Create a for loop that iterates through the query results
- Object: Property
- List name:
newPropList
- For each item, concatenate the property name, followed by a colon, followed by the broker’s email address: <Property Name> : <Broker Email>
- Store the concatenated string in a variable named
propEmail
- Print the
propEmail
variable to the debug log
「How long the property has been on market」のところの指定がよくわからなくてハマったけど、なんとかクリアできたのが以下ソース。
public class PropertyUtility {
public static void newListedProperties() {
// SOQL クエリを作成して、結果を newPropList に格納
List<Property__c> newPropList = [
SELECT Name, Broker__r.Email__c
FROM Property__c
WHERE Days_On_Market__c <= 30
];
// クエリ結果をイテレーション
for(Property__c prop : newPropList) {
// プロパティ名とブローカーのメールアドレスを連結
String propEmail = prop.Name + ' : ' + prop.Broker__r.Email__c;
// 連結した文字列をデバッグログに出力
System.debug(propEmail);
}
}
}
さっきのところは、「Days_On_Market__c <= 30」と指定できてれば良いようです。
コメント