Trying to implement history related list on a custom visual force page, the source code is here github. The problem now i'm facing is that I'm getting an error which I'm not sure what does it means. I have the custom object name called Employee__c
and my VF controller name called EmployeeController
Error:
Unknown property 'EmployeeController.Employee__c'
Page:
<c:GenericHistoryComponent recordLimit1="50" myObject1="{!Employee__c}"/>
Component:
<apex:component controller="GenericHistoryComponentController">
<!-- Attribute Definition -->
<apex:attribute name="myObject1" description="Object we wish to view the history of" type="SObject" required="true" assignTo="{!myObject}" />
<apex:attribute name="recordLimit1" description="Number of lines of history to display" type="Integer" required="false" assignTo="{!recordLimit}" />
<apex:form >
....
</apex:form>
</apex:component>
Class:
public class GenericHistoryComponentController {
// External variables
public SObject myObject {get; set;}
public Integer recordLimit {get; set;}
public Integer updatedRecordLimit {get; set;}
public Integer tableSize {get; set;}
public static String objectLabel {get;}
public Id myObjectId {get;set;}
public Integer rowCount {get;set;}
// Internal Variables
public objectHistoryLine[] objectHistory;
public static final Map<String, Schema.SObjectType> mySObjectTypeMap = Schema.getGlobalDescribe();
public static Map<String, Schema.SObjectField> myObjectFieldMap;
public static List<Schema.PicklistEntry> historyFieldPicklistValues;
public List<objectHistoryLine> getObjectHistory(){
if(updatedRecordLimit != null){
recordLimit = updatedRecordLimit;
}else{
updatedRecordLimit = recordLimit;
}
// if no object passed in, return empty list
if (myObject == null) {
return new List<objectHistoryLine>();
}
myObjectId = String.valueOf(myObject.get('Id'));
Schema.DescribeSObjectResult objectDescription = myObject.getSObjectType().getDescribe();
myObjectFieldMap = objectDescription.fields.getMap();
objectLabel = String.valueOf(objectDescription.getLabel());
//Get the name of the history table
String objectHistoryTableName = objectDescription.getName();
//ID field name
string ObjectIdName;
list<sObject> historyList = Database.query( 'SELECT CreatedDate,'+
'CreatedById,'+
'Field,'+
'NewValue,'+
'OldValue ' +
'FROM ' + objectHistoryTableName + ' ' +
'WHERE ' + ObjectIdName + ' =\'' + myObjectId + '\' ' +
'ORDER BY CreatedDate DESC');
return objectHistory;
}
public PageReference refreshObjectHistory(){
updatedRecordLimit = updatedRecordLimit + recordLimit;
getObjectHistory();
return null;
}
}
{!$ObjectType['Employee__c']
instead of `Employee__cError: Wrong type for attribute <c:generichistorycomponent myObject1="{!$ObjectType['Employee__c ']">. Expected SObject, found String