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
Michael Hedrick 2Michael Hedrick 2 

SOQL against ActivityHistory Object

Hello All,
I am trying to work with the ActivityHistory Object and wanted to confirm what I think the issue is.
I have a query where I want to return records where the record does not contain an activty:
Select Id,Name FROM test__c  WHERE  Status__c='Registered' AND ID NOT IN (SELECT WhatID FROM ActivityHistories where Activity_Subtype__c='stuff')

I am assuming that it is not possible to query against the ActivityHistory object correct?
Best Answer chosen by Michael Hedrick 2
Raj VakatiRaj Vakati
The following objects are not currently supported in subqueries:

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_comparisonoperators.htm?search_text=ActivityHistory


ActivityHistory
Attachments
Event
EventAttendee
Note
OpenActivity
Tags (AccountTag, ContactTag, and all other tag objects)
Task

All Answers

Raj VakatiRaj Vakati
try like this 
 
SELECT (SELECT WhatID FROM ActivityHistories where Activity_Subtype__c='stuff') Id , Name FROM test__c  WHERE  Status__c='Registered'

 
Michael Hedrick 2Michael Hedrick 2
Hey Raj,
Thanks for the reply.  The query you supplied will work.  What I am trying to do is return records from the test__c object where there IS NOT  an Activty associated to it where the activty_subtype__c ''stuff'.
Thanks

 
Raj VakatiRaj Vakati
The following objects are not currently supported in subqueries:

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_comparisonoperators.htm?search_text=ActivityHistory


ActivityHistory
Attachments
Event
EventAttendee
Note
OpenActivity
Tags (AccountTag, ContactTag, and all other tag objects)
Task
This was selected as the best answer