You need to sign in to do that
Don't have an account?

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
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.
I thought that was weird too. We do have history turned on for stage so I guess that will work. Thanks for your help!
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.