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
witoutme247witoutme247 

Parent/Child relationship dynamic query - getting parent values

I have a dynamic query

'SELECT Id,Description, Phone, Otherphone,Account.Phone,ReportsToId, AccountId, ReportsTo.Title,ReportsTo.FirstName,ReportsTo.LastName FROM Contact where Account.Target_Account__c = true and Relevant_Contact__c=true and Phone!=null and OtherPhone!=null and Email!=null and Title!=null and ReportsToId != null and ReportsTo.Title!=null and ReportsTo.FirstName!=null and ReportsTo.LastName!=null'

 

assigned to List<Sobject> scope.

 

When I do a scope.getSobjectType(), it says 'Contact'. Which is fine.

But in my query, I'm also getting the Accounts Phone number and another contacts details (ReportsTo -<lookup onto contact).

How do I get these extra info out of scope? is it possible?

Any help will be greatly appreciated.

Thank you

-VJ

asadim2asadim2
Use the .getSObjects(String childName) method which returns a List<Sobject>.