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
Andrew AldisAndrew Aldis 

SOQL Query on Activity History

I need to pull a query from SF that pulls in the number of activities related to accounts as a count of the number of records and group it by the account owner.  The activity history is a subquery and will not let me aggregate the data.  I am also not able to pull the query directly from activities because it says it in not queryable.  How can I get this to work?

Select
(SELECT OWNER.Name
FROM ActivityHistories
where (ActivityType = 'Discovery Demo' AND ActivityDate=This_month) OR (ActivityType = 'Discovery Interview' AND ActivityDate=This_Month )
)
From Account
Where Target_Account__c = True OR Target_Prospect__c =  True
Bhaswanthnaga vivek vutukuriBhaswanthnaga vivek vutukuri

HI Andrew,

As of my knowledge grouping is not possible for subqueries :( but we can do count

List<Account> acclist = [........query...........];

(acclist[0].AcitivityHistories).size();

What I understood about grouping is - [SELECT OWNER.Name
FROM ActivityHistories
Group by Account.Owner.Name] . Is my understading correct on that ?