function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SurekaSureka 

How to display field label in History related lists in visualforce

Hi All,

 

I am using the below code to display History related lists in visualforce.

<apex:dataTable value="{!Object.histories}" var="history" rowClasses="odd,even" cellspacing="15" width="100%">
<apex:column >
<apex:facet name="header"></apex:facet>
<apex:facet name="footer"></apex:facet>
<apex:outputText value="{0,date,MM/dd/yyyy HH:mm }">
<apex:param value="{!history.createddate}" />
</apex:outputText>
</apex:column>
<apex:column >
<apex:facet name="header">Field</apex:facet>
<apex:facet name="footer"></apex:facet>
<b> <apex:outputText value="{!history.field}"/></b>
</apex:column>
<apex:column >
<apex:facet name="header">Editied By</apex:facet>
<apex:facet name="footer"></apex:facet>
<apex:outputText value="{!history.createdby.name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Old Value</apex:facet>
<apex:facet name="footer"></apex:facet>
<apex:outputText value="{!history.oldvalue}"/>
</apex:column>
<apex:column >
<apex:facet name="header">New Value</apex:facet>
<apex:facet name="footer"></apex:facet>
<apex:outputText value="{!history.newvalue}"/>
</apex:column>
</apex:datatable>

But in "Field" column, its displaying API name of the field. Is there a way to display field label instead of API Name?

 

Or can u suggest any other way to display History related lists with standard controller(without Apex).

 

Thanks

Sureka

 

 

Rajesh ShahRajesh Shah

One way to do that is to use dynamix Apex. The following code is an eg:

 

    // Variables
    public Static final Map<String, Schema.SObjectField> CaseFieldmap = Schema.SObjectType.Case.fields.getMap();
    public Static final List<Schema.PicklistEntry> fieldPicklistValues = CaseHistory.Field.getDescribe().getPicklistValues();
    
    // Function to return Field Label of a Case field given a Field API name
    public Static String returnFieldLabel(String fieldName)
    {
        if(ClassName.CaseFieldmap.containsKey(fieldName))
            return ClassName.CaseFieldmap.get(fieldName).getDescribe().getLabel();
        else
        {
            for(Schema.PicklistEntry pickList : fieldPicklistValues)
            {
                if(pickList.getValue() == fieldName)
                {
                    if(pickList.getLabel() != null)
                        return pickList.getLabel();
                    else
                        return pickList.getValue();
                }
            }
        }
        return '';
    }

 However, this has to be done in Apex Class. So you will have to first store the data in a wrapper class.

 

Also, if you want to generate a history related list like the way standard salesforce does, you can check the following post

http://boards.developerforce.com/t5/Visualforce-Development/History-related-List-using-Visualforce/m-p/156208/highlight/true