Home SALESFORCE SOQL statements cannot query aggregate relationships more than 1 level

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/

You may also like

Leave a Comment