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