カスタム オブジェクト Trainer_ < には、別のカスタム オブジェクト cym__ c への参照フィールドがあります。 Viridian City Gym とそのトレーナー全員のレコードを取得する SOQL クエリはどれですか?
正解:A
Given that Trainer__c has a lookup field to Gym__c, to retrieve the record for the 'Viridian City Gym' and all its trainers, the correct SOQL query is: Option A: SELECT Id, (SELECT Id FROM Trainers__r) FROM Gym__c WHERE Name = 'Viridian City Gym' Parent-to-Child Query (Subquery): To retrieve child records (trainers) from the parent record (gym), you perform a subquery using the child relationship name. Child Relationship Name: For a lookup relationship, the child relationship name can be found in the relationship settings. By default, if the lookup field on Trainer__c is Gym__c, the child relationship name is Trainers__r. Query Breakdown: SELECT Id, (SELECT Id FROM Trainers__r) FROM Gym__c WHERE Name = 'Viridian City Gym' Selects the Gym record and all related Trainers. Why Other Options Are Incorrect: Option B: (SELECT Id FROM Trainer__c) Trainer__c is an object, not a relationship name, so the subquery is incorrect. Option C: SELECT ID FROM Trainer__c WHERE Gym__r.Name = 'Viridian City Gym' This query retrieves Trainer records, not the Gym record and its trainers as specified. Option D: (SELECT Id FROM Trainers__c) Trainers__c is incorrect; the child relationship name should end with __r in subqueries. Reference: SOQL Relationships and Subqueries: "To retrieve related child records, use a subquery in the SELECT clause." - Salesforce SOQL and SOSL Reference: Relationship Queries Conclusion: Option A correctly retrieves the Gym record and all its related Trainer records using a parent-to-child subquery.