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
Preethi77Preethi77 

In my Test Class, I Can able get Opportunity History but cannot able toget CaseHistory record

Opportunity opp = new Opportunity();
 opp.StageName = 'Closed Won';
 opp.Name = 'Testopp';
 opp.CloseDate = system.today();
  Insert opp;
       
List<OpportunityHistory> sd = [ SELECT Id, OpportunityId  FROM OpportunityHistory
                                                         WHERE OpportunityId = :opp.Id ];

 

In my Test Class, I had put this code and I run this code, I can able to get opportunity History record corresponding opportunity.

 

                                         

 

 

Preethi77Preethi77

Case ca = new Case();
ca.status = 'New';   
ca.Origin = 'web';             
Insert ca;
 List<CaseHistory> fd = [ SELECT Id, CaseId  FROM CaseHistory
                                         WHERE CaseId  = :ca.Id ];

But i cannot able to get case history record, i dont know why its happening? Please tel correct solution.

chiranjeevitgchiranjeevitg

After inserting the case in  test code please do some update on the same case.

 

Case ca = new Case();
ca.status = 'New';   
ca.Origin = 'web';             
Insert ca;

ca.type = 'Electrical';

update ca;


 List<CaseHistory> fd = [ SELECT Id, CaseId  FROM CaseHistory
                                         WHERE CaseId  = :ca.Id ];

 

Try the above code and check.

chiranjeevitgchiranjeevitg

do u able to solve this?