I have the following query that works for getting all the Tasks and Events for a Lead.
[SELECT ID, activity_count__c, (SELECT ID FROM Tasks WHERE Status = 'Completed'), (SELECT ID FROM Events) FROM Lead WHERE ID IN :leadIds];
I tried to convert it to get all the Tasks and Events for an Account, like so:
[SELECT ID, activity_count__c, (SELECT ID FROM Tasks WHERE Status = 'Completed'), (SELECT ID FROM Events) FROM Account WHERE ID IN :accountIds];
However, the result was that I only received the Events and Tasks made on the account directly, and not on the objects associated with the account, such as Opportunities, Contacts, Cases, etc.
Is there a way to get all the data from the Account and its associated objects in a single SOQL query? Or, do I need to query each of the associated objects and parse each set of results separately?