4

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;

//### CUSTOM Records LIST CONTROLLER ###
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() {
    Test.StartTest();

        Account oAcc = new Account(Name='APEX_TEST_ACC001');
        insert oAcc;
        ID idAcc = oAcc.Id;
        PageReference newPage = Page.AccountActivities;
        newPage.getParameters().put('Id',String.ValueOf(idAcc));
        Test.setCurrentPage(newPage);

        // 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;
        testExtController.nextRecords();
        testExtController.previousRecords();
        boolean bTest;
        bTest = testExtController.hasNextRecords;
        bTest = testExtController.hasPrevRecords;

        testExtController.showMoreRecords();
        testExtController.showFewerRecords();


    Test.StopTest();
}
}
4
  • It does look like the problem is in my test method. I have commented out from List<ActivityHistory> testRecords to testExtController.showFewerRecords() and it saves without error. Commented Sep 6, 2012 at 14:38
  • Born2BeMild - it's not clear from your comment whether this solves the problem for you or not. Is the controller extension working?
    – metadaddy
    Commented Sep 7, 2012 at 22:01
  • @Born2BeMild if you have solved the problem, you can answer your own question so that it helps the community.
    – Anup
    Commented Sep 10, 2012 at 15:17
  • @Anup unfortunately I've not been able to solve this one yet as without being able to use the ActivityHistory object within a set controller I can't implement a page-able related list. Commented Sep 11, 2012 at 19:26

1 Answer 1

1

It looks like the ActivityHistory object is a special case within salesforce.com. 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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .