I want to access all the related lists in Attendee__c. Also, Attendee__c and Event__c are connected by a junction object called EventAttendee (many-to-many) relationship, I want to print out all the events related to a attendee. Thanks.

  • A screenshot of from your schema builder and any of your current attempts in apex will help analyzing a solution
    – Chris Chen
    Commented Aug 4, 2017 at 1:07

1 Answer 1


Well, assuming you want to do that via Apex, you have to options:

Make a query with nested subqueries such as:

[SELECT Id, (Select Id FROM children__r) FROM Attendee__c WHERE myField__c = 'someValue']

Make consecutive queries for each child object.

Attendee__c[] attendees = [SELECT Id FROM Attendee__c WHERE myField__c = 'someValue'];

Map<Id, Attendee__c> attendeesMap = new Map<Id, Attendee__c>(attendees);

Child__c[] children = [SELECT Id FROM Child__c WHERE Attendee__c IN :attendeesMap.keySet()];

On the one hand, the first option is much more comfortable, but if you're going to manage large datasets, I recommend going with option two since Salesforce highly recommends not using nested queries when the table has a lot of records.

Lastly, given the case that you have an intermediate junction table, then simply chain one more query to get the events. That is, first query for the Attendees, then, with their Ids query for the Event Attendees and lastly, with the Event Attendees, query for the events.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .