I am trying to load all tasks of a contact via SOQL query:
SELECT Id, Subject FROM Task WHERE WhoId = 'contactId'
This query returns only partial list of Tasks. I.e. in UI I see tasks directly attached to this Contact which are not being returned as part of the result for this query.
I googled a bit and found out that I might need to query an ActivityHistory sobject and yes querying it returns me "missing" tasks as well:
SELECT (SELECT Id, Subject FROM ActivityHistories) FROM Contact WHERE Id ='contactId'
So, my question is that an expected behavior? I.e. there is no way to load all the Tasks using 1 query and I have to load both Tasks and AcitivityHistories?
Also, interestingly, I couldn't reproduce this situation in a developer account: I've registered a Task with subject 'other' that took place in the past and in UI it is displayed in Activity History section, but I receive it is a part of normal Task loading query. So, i am not really sure why the Task in originally described situation is not returned with simple Task query (i.e. only in ActivityHistories query)