Find your content:

Search form

You are here

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

 
Share

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();
}
}

Attribution to: Born2BeMild

Possible Suggestion/Solution #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.


Attribution to: Born2BeMild
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/1197

My Block Status

My Block Content