0

this query has 2 subquery (related lists) for teacher and students. teacher_set is the parent and teacher and students are its child object. this is the code:

for (teacher_Set__c tset : [Select Id,name, 
                (Select id, name, first_name__c, room_assignment__c, teacher_set__c from teachers__r WHERE id= :myTea),
                    (Select Id, name, first_name__c, parent__c, teacher_set__c from students__r WHERE id = : selectedSId) 
                        from teacher_set__c ]){}

however, it only returns the Id and name of teacher set. what might be the error please help. thank you

2
  • Why are you saying that nothing comes back? How you looking at the results? Mar 2 '16 at 7:12
  • 1
    may be you are looking for only tset.. You need to check tset.teachers__r and tset.students__r both are list..
    – Ratan Paul
    Mar 2 '16 at 7:15
1

I suggest run below code in your developer console..

And check the result. If you want to access child records,

Use like this

  • tset.teachers__r and
  • tset.students__r

Both are list since One parent Can have multiple childs..

     for (teacher_Set__c tset : [Select Id,name, 
                                     (Select id, name, first_name__c, room_assignment__c, teacher_set__c 
                                      from teachers__r),
                                     (Select Id, name, first_name__c, parent__c, teacher_set__c 
                                       from students__r) 
                            from teacher_set__c ])
    {
       system.debug('----'+tset);   
        system.debug('--teachers__r--'+tset.teachers__r); 
        system.debug('--students__r--'+tset.students__r);  
    }
1
  • 1
    thanks @ratan i have found the items in debug logs. how can i add those in the wrapper if they have different lists? Mar 2 '16 at 8:37
1

When you are iterating through Teacher_Set__c, the object tset contains all the information you queried for:

  • tset.Id
  • tset.Name
  • tset.Teachers__r
  • tset.Students__r
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.