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
Chris987654321Chris987654321 

Opportunity Stage History object

Does the Opportunity Stage History object have any link to the opportunity? When I look in the schema browser in Eclipse and do a query on the Opportunity Stage History I don't see any link to the Opportunity that the history record is associated with.I need to query that object in Apex but I don't see a way to know what record is assocated with what opportunity.

 

Please let me know if there is something I am missing

 

Thanks,

Chris

EnthEnth

Weird never noticed that before, please update the thread if you get an answer. It's almost like the opportunity Id is a hidden field on OpportunityStage.

 

As a possible workaround, you can get the stage history from the OpportunityHistory table, and that does have an opportunityId field .You'd need to switch on field history tracking on Stage to get this, unlike the OpportunityStage which is automatic. 

Chris987654321Chris987654321

I thought that was weird too. We do have history turned on for stage so I guess that will work. Thanks for your help!

bob17bob17

You don't have to turn on Field Tracking to have OpportunityHistory records created.  OpportunityHistory is not the "normal" audit records even thought the table name follows the common "OBJECTHistory" naming schema.  This table contains the speical records that are automatically created any time the key opportunity fields like stage, probability, amount, etc. change.  I suspect this is the data SFDC uses to provide the reportable field like Stage Duration.

 

You can use these records to identify stage changes but you have to be aware that any time ANY of the fields tracked by this special mechanism are modified and the Opportunity saved, a record get written with all the fields populated.  For example, to know if the Stage chnaged, would would have to read the previous OpportunityHistory record in date order to see if the Stage Name was the same as the most recent record (no stage change) of different (a stage change occured).

 

The more traditional "history" record table for Opportunities is called OpportunityFieldHistory.

 

Finally, wouldn't Opportunity Stage History be the audit records of the Stage records themselves?  For example, you changed "Id Decision Maker" to "Identify Decision Maker" or the default probability from 50% to 60%.  The data which feeds the Stage dropdown list is a more complex object then just a collection of strings like most pick lists.

Shivanath DevnarayananShivanath Devnarayanan
Are you using Eloqua ?? may be part of that
Anthony GiulianoAnthony Giuliano
Anyone notice inconsistencies in the data when they export it from the Opportunity History object?  I found at least one Opportunity where the dates/times exported from Opportunity History didn't match the Stage History related list on that opportunity.  This is not due to time zone differences, but various records in Opportunity History for that Opp list Stage 1 with Stage 2's time stamp, Stage 2 listed with Stage 3's time stamp and so on.  When I exported from Opportunity Field History and filter for the Stage field, stage change dates/times matched up properly.
Anthony GiulianoAnthony Giuliano
Oh scratch that.  I think it's showing the "From Stage" field, not the "To Stage", which would explain the discrepancy.  Those fields are distinguishable on Opportunity History Reports, but not as separate fields in Dataloader.io.