Can I create a list of ActivityHistory or OpenActivity records?

  • 1
  • Problem
  • Updated 2 years ago
  • Solved
  • (Edited)
I tried to create a table based on a model of the ActivityHistory object, but I get this error when I try to view the page:
1. An error occurred while attempting to perform the following SOQL query: SELECT Id,ActivityType,IsTask,Subject,Status,Priority,Location,ActivityDate,Description,Owner.Name,OwnerId FROM ActivityHistory WHERE ((WhatId = 'a0Gd000000GApaJEAT')) ORDER BY LastModifiedDate DESC LIMIT 101 Error:entity type ActivityHistory does not support query

Am I not going to be able to do this?
Photo of Peter Bender

Peter Bender, Champion

  • 6,256 Points 5k badge 2x thumb

Posted 6 years ago

  • 1
Photo of Peter Baeza

Peter Baeza

  • 2,868 Points 2k badge 2x thumb
I think that it's only possible to do relationship queries on the history object for example history for one Account, but not for the entire object
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,242 Points 20k badge 2x thumb
The ActivityHistory and OpenActivity objects are actually available for use in Skuid (or in any Visualforce custom development) -- Salesforce exposes them via the API, but they cannot actually be used except for within Salesforce internal code.

Instead, do separate queries on the Task or Event objects. To just get Open Tasks, add an "IsClosed != true" condition, or to get just Completed Tasks, do a Condition with "IsClosed != false".

(I think that in a future release of Skuid we may make it so that these objects don't show up in the list of possibilities, since they don't support querying or any of the CRUD operations).
Photo of Anna Wiersema

Anna Wiersema

  • 10,900 Points 10k badge 2x thumb
Also, I'm currently working on a tutorial for making an "Activities Tab" that will include the Open Tasks and Closed Tasks related lists and some nifty JS snippets (thanks Zach) to mark tasks completed & view the full conversation without leaving the page :) Hopefully it'll get published next week.
Photo of Peter Bender

Peter Bender, Champion

  • 6,256 Points 5k badge 2x thumb
I'm definitely interested in seeing that as soon as you have it.
Photo of Anna Wiersema

Anna Wiersema

  • 10,900 Points 10k badge 2x thumb
Ta da! Here is the tutorial. Let me know if it was helpful.
Photo of Eulogio Gallo

Eulogio Gallo

  • 1,874 Points 1k badge 2x thumb
This tutorial was very helpful! However, I don't see anything about accessing ActivityHistory. Is this something you've been able to resolve since?
Photo of Eulogio Gallo

Eulogio Gallo

  • 1,874 Points 1k badge 2x thumb
I'm having similar issues with trying to load ActivityHistory for a Contact. I'm able to bring in the records as a child relationship under my Contact, but I can't display these records as rows on a table. Any help with this would be appreciated, thanks!
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,242 Points 20k badge 2x thumb
Eulogio,

I think you've gotten about as far as you're able to. Querying the "ActivityHistories" Child Relationship is the best way / only way to get at ActivityHistory data, but Skuid doesn't let you display Child Relationship data as rows in a Table, so your best bet is to use a Template Component to format the data using Merge Syntax to "look" like a table. This is a bit of a hack, that may not look good in the future if Skuid changes its CSS, but it's a temporary workaround.

Here's the XML for a sample page:

<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" showheader="true" tabtooverride="Contact">   
    <models>
        <model id="Contact" limit="1" query="true" createrowifnonefound="false" datasourcetype="salesforce" datasource="salesforce" sobject="Contact" type="">
            <fields>
                <field id="FirstName"/>
                <field id="LastName"/>
                <field id="CreatedDate"/>
                <field id="ActivityHistories" type="childRelationship" limit="10" orderby="LastModifiedDate DESC, ActivityDate ASC NULLS LAST">
                    <fields>
                        <field id="Subject"/>
                        <field id="Status"/>
                        <field id="ActivityDate"/>
                        <field id="Priority"/>
                        <field id="WhoId"/>
                        <field id="WhatId"/>
                        <field id="Who.Name"/>
                        <field id="What.Name"/>
                    </fields>
                    <conditions/>
                </field>
                <field id="Birthdate"/>
                <field id="AccountId"/>
                <field id="Account.Name"/>
            </fields>
            <conditions>
                <condition type="param" enclosevalueinquotes="true" operator="=" field="Id" value="id"/>
            </conditions>
            <actions/>
        </model>
    </models>
    <components>
        <pagetitle model="Contact" uniqueid="sk-3n-oLB-74">
            <maintitle>
                <template>{{FirstName}} {{LastName}}</template>
            </maintitle>
            <subtitle>
                <template>{{Model.label}}</template>
            </subtitle>
            <actions>
                <action type="delete"/>
                <action type="clone"/>
                <action type="share"/>
                <action type="savecancel" window="self"/>
            </actions>
        </pagetitle>
        <basicfieldeditor showsavecancel="false" showheader="true" model="Contact" mode="read" uniqueid="sk-3n-oLC-75">
            <columns>
                <column width="50%">
                    <sections>
                        <section title="Basics">
                            <fields>
                                <field id="FirstName"/>
                                <field id="LastName"/>
                            </fields>
                        </section>
                    </sections>
                </column>
                <column width="50%">
                    <sections>
                        <section title="Other Details" collapsible="no">
                            <fields>
                                <field id="AccountId"/>
                                <field id="Birthdate"/>
                            </fields>
                        </section>
                    </sections>
                </column>
            </columns>
        </basicfieldeditor>
        <template multiple="false" uniqueid="sk-3o1kUh-234" model="Contact" allowhtml="true">
            <contents>&lt;div class="nx-skootable"&gt;
&lt;table class="nx-skootable-data"&gt;
    &lt;thead&gt;
        &lt;tr&gt;
            &lt;th&gt;Subject&lt;/th&gt;
            &lt;th&gt;Date&lt;/th&gt;
            &lt;th&gt;Who&lt;/th&gt;
            &lt;th&gt;Related To&lt;/th&gt;
        &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody class="nx-list-contents"&gt;
        {{#ActivityHistories.records}}
        &lt;tr class="nx-item"&gt;
            &lt;td&gt;{{Subject}}&lt;/td&gt;
            &lt;td&gt;{{ActivityDate}}&lt;/td&gt;
            &lt;td&gt;{{Who.Name}}&lt;/td&gt;
            &lt;td&gt;{{What.Name}}&lt;/td&gt;
        &lt;/tr&gt;
        {{/ActivityHistories.records}}
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;</contents>
        </template>
    </components>
    <resources>
        <labels/>
        <css/>
        <javascript/>
    </resources>
    <styles>
        <styleitem type="background" bgtype="none"/>
    </styles>
</skuidpage>



Here's some example contents of the Template for the Template Component (you have to have "Allow HTML" enabled):

<div class="nx-skootable">
<table class="nx-skootable-data">
    <thead>
        <tr>
            <th>Subject</th>
            <th>Date</th>
            <th>Who</th>
            <th>Related To</th>
        </tr>
    </thead>
    <tbody class="nx-list-contents">
        {{#ActivityHistories.records}}
        <tr class="nx-item">
            <td>{{Subject}}</td>
            <td>{{ActivityDate}}</td>
            <td>{{Who.Name}}</td>
            <td>{{What.Name}}</td>
        </tr>
        {{/ActivityHistories.records}}
    </tbody>
</table>
</div>
Photo of Eulogio Gallo

Eulogio Gallo

  • 1,874 Points 1k badge 2x thumb
Thanks Zach, this was perfect! I didn't think of using templates for this, that was a great idea.

In case anyone tries something like this in the future, make sure you include AcitvityHistories as a child relationship in your model, and set Properties > Fields to Order Records By to "ActivityDate DESC NULLS LAST, LastModifiedDate DESC", otherwise you'll get an error.