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
stormrider_05stormrider_05 

How do I get only Accounts which have a specific Activity in their ActivityHistory

Hello,

 

Is there a way to find only those Accounts which have an Activity of a certain type in their ActivityHistory and exclude the ones that don't?

 

My current query looks like this:

 

SELECT Id, Name, ( SELECT Id, ActivityType, ActivityDate, Description, Status, Owner.Id, Owner.Name FROM ActivityHistories WHERE ActivityType = 'my_activity_type' ORDER BY

ActivityDate DESC ) FROM Account



What I want is only Accounts where ActivityHistories is not empty. e.g WHERE AccountHistories != null or so.

 

I know that I could just collect the Ids of the relevant accounts manually and do a second query. But since the number of Accounts in the system is > 40000 I'd rather get it all done in one step.

 

Thank you for your help!

 

Best Answer chosen by Admin (Salesforce Developers) 
JimRaeJimRae

According to the API documentation, ActivityHistory is not supported in a semi join subquery, so you will be forced to use 2 queries to process your data.

 

The following objects are not currently supported in subqueries:

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



All Answers

JimRaeJimRae

According to the API documentation, ActivityHistory is not supported in a semi join subquery, so you will be forced to use 2 queries to process your data.

 

The following objects are not currently supported in subqueries:

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



This was selected as the best answer
stormrider_05stormrider_05

Thanks for your help!