You need to sign in to do that
Don't have an account?

Can't access data obtained in a nested query
I have this query
List <Booking__C> bk = [Select (Select Contact__c From Pupils__r) From Booking__c b where b.id = :bookingId];
This query should return me the related Contact ID's from Pupils sObject which is a Child Object for Booking and I'm saving the result in a List of type Booking__c, but how do I access the result of related records in another query, if I want to run another query with the results of this one
For Eg:
List <contact> con = [select firstname, lastname, id from contact where id = ??? (I have tried bk.Contact__C, also tried bk.Pupils__r.id - nothing works, it comes up with an error)
I'm new to salesforce can't get my head around accessing nested query results.
I'll be glad if any one can tell me where I'm going wrong.
Thanks
This will give u the pupils for the first record of bookings. Use a for loop to get all the pupils.