Codementor Events

How to resolve Salesforce ActivityHistory Query Issue?

Published Jul 26, 2024

We have sometimes need to get the data from Activity History that is lined up on each object detail page which can be used to track the Email, Appointment, meetings or phone calls. Now Salesforce doesn’t allow this direct quering of this object for any matter of reason, could be data bulk size that can hit as this is a general purpose object available in almost all standard or custom objects in Salesforce.

So if you Run the query below.

SELECT Id FROM ActivityHistory

You should see the following error

INVALID_TYPE: 
SELECT Id, Description FROM ActivityHistories
                            ^
ERROR at Row:1:Column:29
sObject type 'ActivityHistories' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.

How to resolve “INVALID_TYPE : sObject type ‘ActivityHistories’ is not supported”

So when we need to check the records of the ActivityHistory objects, then we need to use the parent object and put this ActivityHistory in the sub query of the object we are dealing with. So in our example we are using Contact. We can use any object, it could be custom or standard object the query format will remain same for all the objects like below.

SELECT Id, (SELECT Id, Description FROM ActivityHistories) FROM Contact

Same way if we are dealing with object like Case then the query would become like this

SELECT Id, (SELECT Id, Description FROM ActivityHistories) FROM Case

Now to work on the record then you can play around with some apex code with which you can filter out the child records(ActivityHistory).

Additionally, Salesforce recommends a number of filters and particular sorting when sub querying ActivityHistory records. Do check out their latest recommendations  on this link here

Peace ✌️

Discover and read more posts from Sunil Kumar
get started