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
AlisonRAlisonR 

INVALID_TYPE_FOR_OPERATION: entity type ActivityHistory does not support query

So I've created an controller extension and have added a visualforce page to my account layout. It all works fine and dandy except for a few accounts I get this error: "Content cannot be displayed: INVALID_TYPE_FOR_OPERATION: entity type ActivityHistory does not support query". I believe it has to do with the fact that the accounts that seem to error have a large amount of activity history. However, when I add a LIMIT to the controller extension it still errors. How do we fix this?

 

Apex Class:

 

public class AccountSalesActH {
    
    private final Account acct;
    
    public AccountSalesActH(ApexPages.StandardController stdController) {
        this.acct = (Account)stdController.getRecord();
    }

    public String getName() {
        return 'AccountSalesActH';
    }
        
    public Account getAccount() {
        Account[] acct = [select id, name, ownerid,
                    (select subject, whatid, whoid, activitydate, LVM__c, ownerid, lastmodifieddate from ActivityHistories 
                     where ownerid not in ('00530000000vpI1') order by activitydate DESC ) //filter out marketing actvities 
                from Account
                where id = :ApexPages.currentPage().getParameters().get('id')]; if (acct.size()>0) {return acct[0];} else {return null;
    }

}}

 

Visualforce page:

 

<apex:page standardController="Account" extensions="AccountSalesActH">
<br />

<apex:pageBlock title="Sales Activity History">
<div style="padding-left:33%">
<apex:outputLink styleClass="btn" onclick="window.parent.location='/00T/e?title=Call&who_id={!Account.Id}&followup=1&tsk5=Call&retURL=%2F{!Account.id}'" style="text-decoration:none">Log a Call</apex:outputLink>
<apex:outputLink styleClass="btn" onclick="window.parent.location='/apex/accountsales?id={!Account.Id}'" style="text-decoration:none">View All</apex:outputLink></div><br />

<apex:pageBlockTable value="{!Account.ActivityHistories}" var="hist" rows="5">
<apex:column headerValue="Action">
      <apex:outputLink value="/{!hist.Id}/e?retURL=/apex/{!$CurrentPage.Name}" target="_parent" style="color: #015ba7;
text-decoration: none;
font-weight: normal;">Edit</apex:outputLink> <span style="color:#999">|</span>&nbsp;
      <apex:outputLink value="/{!hist.Id}" target="_parent" style="color: #015ba7;
text-decoration: none;
font-weight: normal;">View</apex:outputLink>
</apex:column>

            <apex:column value="{!hist.subject}"/>
            <apex:column value="{!hist.whoid}"/>
            <apex:column value="{!hist.activitydate}"/>
            <apex:column value="{!hist.LVM__c}"/>
            <apex:column value="{!hist.ownerid}"/>
            <apex:column value="{!hist.lastmodifieddate}"/>  
    </apex:pageBlockTable><br />
    <apex:outputLink onclick="window.parent.location='/apex/accountsales?id={!Account.Id}'">Go to List >></apex:outputLink>
    <base target="_parent"/>
</apex:pageBlock>


</apex:page>
                      

 

Sonam_SFDCSonam_SFDC

Activity History Table cannot be accessed directly but as a sub query from a parent object.

 

Read more on the following link - it gives a good sample which would help you alter your code accordingly:

http://salesforce.stackexchange.com/questions/8327/accessing-email-sent-in-activity-history-via-api

AlisonR3AlisonR3

It is a subquery of a parent object (Account). This has to do with the fact that Visualforce will only display 1,000 rows, how do I limit my collection to only return 1,000.