0

I am trying to query Opportunity Field History to get the results for a custom lookup field that has history tracking. I am getting 2 records back for 1 single change, one of the record has oldvalue and newvalue as lookup id and another record has lookup name as old and new value. I was wondering why Field history is creating 2 records for same change. I am trying to query it and set the resulting list to a front end table, but since it is returning 2 values for single change there is a duplicate value displayed. how can i restrict that?

my query looks like this select id, OldVlaue, NewVlaue from OpportunityFieldHistory where OpportunityId='oppID'

2
  • Try adding the Field column into your query, it should tell you the tracked field of each row. I assume they are not the same field. – Hengky Ilawan Jun 29 '20 at 0:54
  • I added Field column to the query query it still shows me 2 records for the same tracked lookup field one with id for old value and new value for lookup field and one with name value of the lookup field in old value and new value – aakash poudel Jun 29 '20 at 1:07
0

This is "working-as-designed"

For example, field history on Opportunity.OwnerId will return two records

OldValue      NewValue
----------     --------
oldId          newId
oldOwner.Name  newOwner.Name  // facilitates display in the Related List

Since you can't filter on OldValue or NewValue in the query; you'll need to post-process in Apex, testing OldValue / NewValue to see if they cast to ID type

try {
   Id oldValAsId = (Id) fieldHistoryItem.OldValue;
}
 catch (Exception e) { // ignore item  }

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.