0

The below codes work fine in a brand new VF page as shown below:

<apex:page standardController="Employee__c" >
    <c:GenericHistoryComponent my_Object="{!Employee__c}" record_Limit="50"></c:GenericHistoryComponent>
</apex:page>

But my question is, how would you make it work to an existing VF page?

Getting this error:

Error: Unknown property

<apex:page standardController="Visitor__c">
 .....
 <c:GenericHistoryComponent my_Object="{!Employee__c}" record_Limit="50"> </c:GenericHistoryComponent>
</apex:page>

My component looks like this:

<apex:component controller="GenericHistoryComponentController">

    <!-- Attribute Definition -->
    <apex:attribute name="myObject" description="Object we wish to view the history of" type="SObject" required="true" assignTo="{!myObject}" />
    <apex:attribute name="recordLimit" description="Number of lines of history to display" type="Integer" required="false" assignTo="{!recordLimit}" />

    <apex:form >
        <!-- Object History Related List -->
        <apex:pageBlock id="historyTable" title="{!objectLabel} History">
            <apex:pageBlockTable value="{!ObjectHistory}" var="History" >
                <apex:column headerValue="Date"  value="{!History.thedate}"/>
                <apex:column headerValue="User">
                    <apex:outputLink value="/{!History.userId}"> {!History.who} </apex:outputLink> 
                </apex:column>
                <apex:column headerValue="Action"><apex:outputText escape="false" value="{!History.action}"/></apex:column>
            </apex:pageBlockTable>

            <apex:outputPanel rendered="{!tableSize > rowCount}">
               <div class="pShowMore">
                    <apex:commandLink value="Show more »" rerender="historyTable" action="{!refreshObjectHistory}">
                    </apex:commandLink>
                    &nbsp;|&nbsp;
                    <a href="/_ui/common/history/ui/EntityHistoryFilterPage?id={!myObjectId}">Go to list&nbsp;»</a>
               </div>
            </apex:outputPanel>
        </apex:pageBlock>
    </apex:form>
</apex:component>
0

Assuming the component and its GenericHistoryComponentController will work with any type of object, you just need to supply an SObject reference. For a standard controller. That reference is given the same name as the type that is specified by the standardController attribute.

So for this to work with your existing page it's:

<apex:page standardController="Visitor__c">
     ...
     <c:GenericHistoryComponent my_Object="{!Visitor__c}" record_Limit="50">
     </c:GenericHistoryComponent>
</apex:page>

PS

On the subject of displaying the history of a different object, if there is a field reference to one instance (i.e. a parent) you could do this:

<apex:page standardController="Visitor__c">
     ...
     <c:GenericHistoryComponent my_Object="{!Visitor__c.Employee__r}" record_Limit="50">
     </c:GenericHistoryComponent>
</apex:page>

but if not you will have to write a controller extension that provides a property to the single instance.

  • it will work with any type of object you can see the code here github.com/pcjones10/Genteric-History-Component/tree/master/… but why would you use the same custom object? the purpose of this component to get the tracking history based on what object you are passing to the component, I'm confused now – Nick Kahn Jan 6 '17 at 23:15
  • don't you think if you provide Visitor__c custom object it will return you the Visitor__c related history tracking? but in my case I want the Employee__c – Nick Kahn Jan 6 '17 at 23:16
  • @NickKahn Yes it will - see the PS I added. – Keith C Jan 7 '17 at 0:40
  • Thanks but there is no reference to employee and visitor object that's my concern – Nick Kahn Jan 7 '17 at 0:47
  • @NickKahn If there is no logic relationship then the design makes no sense. But if there is a logical relationship, then you can write Apex code in a controller extension that queries to find the corresponding employee and makes that available in the page via a property. – Keith C Jan 7 '17 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.