You need to sign in to do that
Don't have an account?
looping thorugh sub query
Hi all,
Okay so I'm pretty weak at using sub query and usually avoid this. So I will need a little help on this.
If I understand correctly the error is saying Job.job_contact__c is not a list. How do I check through the sub query?
Okay so I'm pretty weak at using sub query and usually avoid this. So I will need a little help on this.
List<Job__c> jobs = [SELECT ID, Contact__c, Project_site_contact_name__c, (SELECT ID, Contact__c FROM Job_Contacts__r) FROM Job__c WHERE ID in :updateContactIds]; for (Job__c job : jobs) { for(Contact con : jobs.job_contacts__r) { } {So here's the little code snippet. I the 2nd for loop is giving me error saying "Initial term of field expression must be a concrete SObject: LIST<Job__c>"
If I understand correctly the error is saying Job.job_contact__c is not a list. How do I check through the sub query?
In your code you write jobs.job_contacts__r you created a new instance for jobs that is job so use job.job_contact__r.
and this is a type of job_Contact__c sobject so in 2nd for loop you must have to use for(job_contact__c con : job_job_contacts__r)
so try this code
All Answers
for(Contact con : jobs.job_contacts__r)
It should be job instead of jobs:
for(Contact con : job.job_contacts__r)
In your code you write jobs.job_contacts__r you created a new instance for jobs that is job so use job.job_contact__r.
and this is a type of job_Contact__c sobject so in 2nd for loop you must have to use for(job_contact__c con : job_job_contacts__r)
so try this code
http://www.cloudforce4u.com/2013/06/sometimes-we-need-list-of-all-child.html