Wednesday, May 18, 2011

Salesforce - Display the History related lists in visualforce


To display the Account History Related lists,
<apex:page standardController=”Accounts”>
<!—Displays Accounts History Related lists -- >
<apex:dataTable value="{!Account.histories}" var="accountHistory" width="100%">
                 <!—Displays Created Date of the Field History -- >
                <apex:column>
                                <apex:facet name="header">Date</apex:facet>
                                <apex:outputText value="{0,date,MM/dd/yyyy HH:mm }">
                                                <apex:param value="{!accountHistory.createddate}" />
                                </apex:outputText>
               </apex:column>
              <!—Displays the corresponding field -- >
              <apex:column >
                 <apex:facet name="header">Field</apex:facet>
                                 <b> <apex:outputText  value="{!IF(CONTAINS(accountHistory.field,'__c'),LEFT(accountHistory.field, LEN(accountHistory.field) -3),accountHistory.field)}"/></b>
            </apex:column>
            <!—Displays Edited By User-- >                        
            <apex:column >
                <apex:facet name="header">Edited By</apex:facet>
                <apex:outputText value="{!accountHistory.createdby.name}"/>
            </apex:column>
            <!—Displays Old value of the field -- >
            <apex:column >
                <apex:facet name="header">Old Value</apex:facet>
                <apex:outputText value="{!accountHistory.oldvalue}"/>
            </apex:column>
            <!—Displays New Value of the field -- >
            <apex:column >
                <apex:facet name="header">New Value</apex:facet>
                <apex:outputText value="{!accountHistory.newvalue}"/>
            </apex:column>
        </apex:datatable>
    </apex:pageblock>   
</apex:page>

No comments:

Post a Comment