SOQL statements cannot query aggregate relationships more than 1 level away from the root entity object.

SOQL QUERY:

Example1:

SELECT Id, Name,
(SELECT WhoId, WhatId, Subject, AccountId,
(SELECT Id, EventId, RelationId, Status From EventRelations)
From Events where ActivityDateTime <> null)
From Account

if using above query and its through the following SOQL error:

SOQL statements cannot query aggregate relationships more than 1 level away from the root entity object.

Example2:

SELECT Id,
(SELECT Id,FirstName,LastName,
(SELECT Id,Subject FROM ActivityHistories)
FROM Contacts)
FROM Account

This isn’t a legal syntax (you can’t query more than one level down). Instead, you need to query the data in a controller or extension and then expose the data using Wrapper Class

For Example:
http://forums.sforce.com/t5/forums/forumtopicprintpage/board-id/general_development/message-id/55159/print-single-message/false/page/1
http://blog.jeffdouglas.com/2010/02/22/soql-how-i-query-with-thee-let-me-count-the-ways/

Written by 

I am Sakthivel Madesh, a certified Salesforce Advanced Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 15x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead 5x Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply

Your email address will not be published. Required fields are marked *

*