Find your content:

Search form

You are here

How can I use a standard set controller with ActivityHistory records?


I want to display a custom related list on my account detail page that mimics the standard Account History related list with a few enhancements.

I want to enable pagination so I have defined a custom controller extension to provide this functionality. This uses a StandardSetController which I am trying to instantiate from the current record's ActivityHistory child relationship.

However when I try to save my code I'm getting this error message.

Object type 'ActivityHistory' is not supported by standard controllers

What can I do to resolve this issue? Is it possible for me to create a custom set controller that inherits from the standard one?

Here is my controller

public with sharing class AccountActivityHistoryExt {
public AccountActivityHistoryExt(ApexPages.StandardController controller) {
    //agent controller code to go here
    this.acc = (Account) controller.getRecord();

//get URL parameters
public ID idAcc = ApexPages.currentPage().getParameters().get('id');
private final Account acc;

//set public page size parameter
public Integer pageSize = 10;
public Integer resCount {get {return relatedRecords.getResultSize();} set;}
public boolean refreshRequired = false;

public ApexPages.StandardSetController relatedRecords {
    get {
        //if (relatedRecords==null) {
        if (relatedRecords==null || refreshRequired) {                                                                                          
            List<ActivityHistory> recList = new List<ActivityHistory>();
            recList = acc.ActivityHistories;

            relatedRecords = new ApexPages.StandardSetController(recList);
            if (pageSize!=null) {relatedRecords.setPageSize(pageSize);}

        return relatedRecords;
    private set;


//get the Records records
public ActivityHistory[] getActivityHistoryRecords() {
    return (ActivityHistory[])relatedRecords.getRecords();

public static TestMethod void testAgentFunds() {

        Account oAcc = new Account(Name='APEX_TEST_ACC001');
        insert oAcc;
        ID idAcc = oAcc.Id;
        PageReference newPage = Page.AccountActivities;

        // page controller
        ApexPages.StandardController testStdController = new ApexPages.StandardController(oAcc);
        AccountActivityHistoryExt testExtController = new AccountActivityHistoryExt(testStdController);

        // agent fund portfolio
        List<ActivityHistory> testRecords;
        testRecords = testExtController.getActivityHistoryRecords();
        System.assertEquals(testExtController.resCount, testRecords.size());

        ApexPages.StandardSetController testRecordsController = testExtController.relatedRecords;
        boolean bTest;
        bTest = testExtController.hasNextRecords;
        bTest = testExtController.hasPrevRecords;



Attribution to: Born2BeMild

Possible Suggestion/Solution #1

It looks like the ActivityHistory object is a special case within It combines completed tasks with events that occurred in the so it may be some sort of view or alias to the Task and Event objects.

Perhaps because of this it does not appear to be possible to build a custom set controller extension over the ActivityHistory object.

The only option then is to build a custom controller that collects records from the Task and Event objects and combining them into a single record set. This could then be used to provide a page-able custom related list.

Attribution to: Born2BeMild
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content