-1

I'm trying to print sub query fields but I got the error like "Loop must iterate over collection: Webinar_Attendees__c".

          list<Webinar_Attendees__c> re = [SELECT Id,Login__c,Name,Opportunity__c,WebinarContact__c,Voucher_Number__c,Email_Sent__c, LastModifiedDate,(select Id,Name,Voucher_Assign_Date__c    from Voucher_Repository__r  )
                                     FROM Webinar_Attendees__c WHERE Voucher_Number__c != Null AND CreatedDate <= TODAY 
                                     ORDER BY LastModifiedDate DESC NULLS FIRST LIMIT : limitsize OFFSET : count];   

     for(Webinar_Attendees__c web : re){

         for(Voucher_Repository__c rep : web){

            Date dateField = rep.Voucher_Assign_Date__c;

         }
     }

Thanks, RAGHU

1

web is a variable of type Webinar_Attendees__c. It is not a collection, and cannot be used in an iteration. To access subquery results, you must use the relationship name given in the child query as a property on the parent. This value will be typed as a List<sObject>, where the sObject is the type of the child object.

     for(Voucher_Repository__c rep : web.Voucher_Repository__r){

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.