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
Richa_LearningRicha_Learning 

History related list on VF page

Hi,

our developer has created this apex class on custom object (Invoice Client) so we can track field history tracking . On this object  when we change status__c field then history is captured. We want to track history for other fields too. What is the easiest way to inlcude other fields so we can track history on it?
public with sharing class invoice 
{       
    private final string sFieldHistoryTrackObjName = 'Invoice_client';
    private final string sFieldHistoryTrackFldName = 'Status__c';  
    
    
 
    public string sHistoryTrackObjectName
    {
        get
        {
            return sFieldHistoryTrackObjName;
        }
    
    }
   
    public List<string> HistoryTrackFieldName
    {
        get
        {
            
            return new string[]{sFieldHistoryTrackFldName};
        }
    
    } 
}

Thanks.
Richa
Best Answer chosen by Richa_Learning
Swayam@SalesforceGuySwayam@SalesforceGuy
Hi,

You can use this updated code 
public with sharing class invoice 
{       
    private final string sFieldHistoryTrackObjName = 'Invoice_client';
    private final string sFieldHistoryTrackFldName = 'Status__c';  

//Add New Variable For API NAme
    private final string sFieldHistoryTrackFldNameOne = 'New Field API Name';  
    
    
 
    public string sHistoryTrackObjectName
    {
        get
        {
            return sFieldHistoryTrackObjName;
        }
    
    }
   
    public List<string> HistoryTrackFieldName
    {
        get
        {
         //Add to String Array   
            return new string[]{sFieldHistoryTrackFldName, sFieldHistoryTrackFldNameOne };
        }
    
    } 
}
Hope this help

Please let me know, in case any issue

--
Thanks
​Swayam               

All Answers

Swayam@SalesforceGuySwayam@SalesforceGuy
Hi,

You can use this updated code 
public with sharing class invoice 
{       
    private final string sFieldHistoryTrackObjName = 'Invoice_client';
    private final string sFieldHistoryTrackFldName = 'Status__c';  

//Add New Variable For API NAme
    private final string sFieldHistoryTrackFldNameOne = 'New Field API Name';  
    
    
 
    public string sHistoryTrackObjectName
    {
        get
        {
            return sFieldHistoryTrackObjName;
        }
    
    }
   
    public List<string> HistoryTrackFieldName
    {
        get
        {
         //Add to String Array   
            return new string[]{sFieldHistoryTrackFldName, sFieldHistoryTrackFldNameOne };
        }
    
    } 
}
Hope this help

Please let me know, in case any issue

--
Thanks
​Swayam               
This was selected as the best answer
Richa_LearningRicha_Learning

Hi Swamay - thanks this works.

but the issue is, I am trying to track history of a field that has lookup to user. So when i change user it shows me the history
but with 2 rows (one with user id and one with name) . I only want to see only name.
 
public with sharing class invoice 
{       
    private final string sFieldHistoryTrackObjName = 'Invoice_client';
    private final string sFieldHistoryTrackFldName = 'Status__c';  

//Add New Variable For API NAme
    private final string sFieldHistoryTrackFldNameOne = 'users__c';  
    
    
 
    public string sHistoryTrackObjectName
    {
        get
        {
            return sFieldHistoryTrackObjName;
        }
    
    }
   
    public List<string> HistoryTrackFieldName
    {
        get
        {
         //Add to String Array   
            return new string[]{sFieldHistoryTrackFldName, sFieldHistoryTrackFldNameOne };
        }
    
    } 
}

 
Swayam@SalesforceGuySwayam@SalesforceGuy
Hi,

Getting two rows is some thing different, Can you share API code where you are accessing the field and object.


--
Thanks,
Swayam
Richa_LearningRicha_Learning
Sorry i didnt get what you are requesting? I have already shared the apex class code....
Swayam@SalesforceGuySwayam@SalesforceGuy

I mean above class is calling from some another Apex code, where there must be query to get the history. 

Also. Can you please resolve this one and open a  question with that,

--
Thanks,

Swayam

 

Richa_LearningRicha_Learning
I checked in my org. for account (VF page) also, if we change any lookup field than id and actual value shows up.....so is there a way on vf page to show only value when changing value for lookup fields.
Swayam@SalesforceGuySwayam@SalesforceGuy
Can you share VF page code