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

Is it possible to populate test data in OpportunityHistory Object ?
To populate test data in OpportunityHistory Object I tried following code
date myDate = date.newInstance(1960, 2, 17);
Opportunity oppInst = new Opportunity(Name = 'test opp',StageName = 'Prospecting',CloseDate = myDate);
insert oppInst;
oppInst.StageName = 'Qualification';
update oppInst;
List<OpportunityHistory> oppHist = [SELECT id from OpportunityHistory];
System.debug(' test oppHist size : ' + oppHist );
This works when run as anonymous code , it works.
When I run it from within a test class it does not work...
Is there any way we can populate OpportunityHistory with test data ?
Thanks in advance!
Unfortunately not. The history table is populated when the transaction containing field changes completes. As you can't complete transactions when testing, it isn't possible to populate the table.
Thank you bob for your reply.