Salesforce Certified Platform Developer I — Question 1
A custom object Trainer_c has a lookup field to another object Gym_c.
Which SOQL query will get the record for the Viridian Gym and all it’s trainers?
Answer options
- A. SELECT Id, (SELECT Id FROM Trainer_c) FROM Gym_c WHERE Name = ‘Viridian City Gym’
- B. SELECT Id, (SELECT Id FROM Trainers_c) FROM Gym_c WHERE Name = ‘Viridian City Gym’
- C. SELECT ID FROM Trainer_c WHERE Gym_r.Name = ‘Viridian City Gym’
- D. SELECT Id, (SELECT Id FROM Trainers_r) FROM Gym_c WHERE Name = ‘Viridian City Gym’
Correct answer: D
Explanation
Option D is correct because it properly references the relationship using the correct child relationship name 'Trainers_r' to fetch trainers linked to the Gym_c record. Option A incorrectly uses 'Trainer_c' instead of the relationship name, while B uses 'Trainers_c' which is not the correct relationship name. Option C does not return the Gym_c record and instead queries only the Trainer_c records, making it incorrect for this requirement.