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
O2O SimonO2O Simon 

Select data from ActivityHistory

Hi,

I am trying to add a new button in Lead detail page, to view all the activity history with subject equals to "Call".

This is the query string i used in the S-controls :

var queryResult = sforce.connection.query("Select ActivityDate, Description, Subject, Status from ActivityHistories Where Subject = 'Call' And Status = 'Completed' And id='{!Lead.Id}' ");

But it failed, could anyone suggests what is the problem of the query string?

Thank you very much.

Simon
JimRaeJimRae

I don't think you can use activityhistory as a query table, you probably need to use Task.

var queryResult = sforce.connection.query("Select ActivityDate, Description, Subject, Status from Task Where Subject = 'Call' And Status = 'Completed' And ActivityDate < Today And id='{!Lead.Id}' ");

To get the "history" part, you use the Activitydate< Today part of the filter.
 
Good Luck!
werewolfwerewolf
The table is called "ActivityHistory," not "ActivityHistories."  Try your query in Force.com Explorer or the Force.com IDE to test it before putting it in code.
JimRaeJimRae
I tried that first, and get an error that ActivityHistory is not queryable.
SuperfellSuperfell
ActivityHistory is not queryable as a top level object, only as a related sub query, e.g.

select id, subject, (select subject, activityDate from activityHistories) from case

Message Edited by SimonF on 09-21-2008 10:15 PM