I am doing some pipeline research and basically need to create a "snapshot" using the opportunity history table. So I look for the the max created date prior to my chosen date. I get occasionally get more than 1 row per opportunity returned. Are records in this table created in batches? I just don't understand how two rows can be written at the same second.
1 Answer
Take a look at the documentation on OpportunityHistory
:
Usage
This object represents the history of a change to the Amount, Probability, Stage, or Close Date fields of an Opportunity. The OpportunityFieldHistory object represents the history of a change to any of the fields of an Opportunity. To obtain information about how a particular opportunity is progressing, query the OpportunityHistory records associated with a given Opportunity. Please note that if an opportunity's Amount, Probability, Stage, or Close Date fields have not changed, nothing will be returned in the OpportunityHistory objects. In this case, query the OpportunityFieldHistory records associated with a given Opportunity to get more information about changes to the opportunity.
So there are a few different scenarios to consider:
- Zero
OpportunityHistory
records exist for a specificOpportunity
record- The Amount, Probability, Stage, and Close Date fields have not changed since the record was created
- Exactly one
OpportunityHistory
record exists for a specificOpportunity
record- Of all the above mentioned fields, only one transaction has changed any of the values.
- More than one
OpportunityHistory
record exists for a specificOpportunity
record- Multiple transactions have changed the values of the aforementioned fields.
You are by no means guaranteed a one-to-one ratio.