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
Puneet SardanaPuneet Sardana 

Retrieving field history of custom object through apex

Hi,

 

I am trying to retrieve history of field Salary at my custom object Employee. I am using the following query :-

 

List<Employee__c> lstEmp=[SELECT Id,Salary__c,
                          (SELECT OldValue,NewValue, FROM Histories)
                          FROM Employee__c                        
                         ];

Now I need to retrieve a particular field only which is salary, I do not want other fields tracking details and I need to get date at which the change is made. Please let me know how should i modify my query and if you have the link to the documentation of history object present in salesforce please post that.

 

 

Thanks in advance....

Best Answer chosen by Admin (Salesforce Developers) 
TejTej

Try this,

 

SELECT ParentId, OldValue, NewValue, Field, CreatedById, CreatedDate FROM Employee__History where parentId = :EmployeeId and Field = 'Salary__c'

 

hope this helps.

All Answers

TejTej

Try this,

 

SELECT ParentId, OldValue, NewValue, Field, CreatedById, CreatedDate FROM Employee__History where parentId = :EmployeeId and Field = 'Salary__c'

 

hope this helps.

This was selected as the best answer
Puneet SardanaPuneet Sardana
Thanks...that solved my problem. Do you have a link that has details about this history object?
TejTej

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_leadhistory.htm

this might give you some idea.

 

if you open your schema in IDE or if you have force.com explorer, you can see the history object available for each standard/custom object