function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Timothy SmithTimothy Smith 

SOQL subquery access variables

Attempting to access the variables MIlestone1_Project__c has a Lookup relationship to Account with relationship name: `Projects__r'.
 
List<Account> accList = [SELECT Id, Name, EHR_Status__c, PM_Status__c,
                                    Project_Imp_Status__c, Other_Status__c,(select Client_Advisor_Email__c,
                                                                                 Resource_Coordinator_Email__c
                                                                                 from Projects__r) 

                             FROM Account
                             WHERE Id IN :AcctIds];
 
List<String> emailAdds = new List<String>();
                 for (Account al: accList) {
                    emailAdds.add(al.Projects__r.Client_Advisor_Email__c);
                    emailAdds.add(al.Projectss__r.Resource_Coordinator_Email__c); 
                 }



Any help is greatly appreciated.
 
Best Answer chosen by Timothy Smith
Boss CoffeeBoss Coffee
Projects__r will be a list for each Account, so it'll be something like the following.
for(Account al : accList) {
  for(Project__c proj : al.Projects__r) {
    emailAdds.add(proj.Client_Advisor_Email__c);
    // ...etc
  }
}