I'm trying to get SOQL's for Activities (workbench was no help).
I'm looking at the three prebuilt reports in Salesforce:
Activities on Leads
, Activities on Accounts
, and Activities on Opportunitites
and would like to see "open & completed activites", both "Events & Tasks", as well as a date frame for Activity Date in THIS_YEAR.
My best guess are for eg 'Activities on Leads' is:
SELECT Report_Country_L__c, (SELECT Owner.Name,ActivityDate,Status,istask,TaskSubtype,
Subject FROM Task WHERE ActivityDate = This_Year) FROM Lead
But it does not work!
Any idea?
Best Answer
The object you should query is OpenActivity and ActivityHistory
So your query should be
EDIT:
If you want to retrieve both
Events
andTasks
without considering whether itsOpen
orCompleted
, you can go with Devendra's approach. If your consideration if to get onlyOpen
orCompleted
Events
andTasks
, then you can go with the above approach. In this case you should only include eitherActivityHistories
orOpenActivities
subquery.Hope it helps.