+ Start a Discussion
rekha sharmarekha sharma 

Test class OpportunityApprovalHistoryController

I am going through blog  http://vaibhav-deep.blogspot.in/2011/01/capture-approvalrejection-comments-in.html 

please help me in creating  the test class of the following class.


public class OpportunityApprovalHistoryController {
public String opptyId {get;set;}
public List<ProcessInstanceHistory> getApprovalSteps() {
if (opptyId != null) {
Opportunity quote = [Select Id, (Select TargetObjectId, SystemModstamp, StepStatus, RemindersSent, ProcessInstanceId, OriginalActorId, IsPending, IsDeleted, Id, CreatedDate, CreatedById, Comments, ActorId From ProcessSteps order by SystemModstamp desc) from Opportunity where Id = :opptyId];
return quote.ProcessSteps;
return new List<ProcessInstanceHistory> ();



Siddharth Birari.ax1164Siddharth Birari.ax1164

Hi Rekha,


For your test code development the very first thing that you need is test data..

here i can see, there are two objects coming into the picure.

1) Opportunity (Parent)

2) ProcessSteps (Child)


First create the test data for Opportunity. (Preferably only one record)


Create  few test records for ProcessSteps object and associate those with the Opportunity record created in first step.

Uptil now, you are good to have test data.


Create instance of OpportunityApprovalHistoryController


OpportunityApprovalHistoryController obj = new OpportunityApprovalHistoryController();

Assign the Opportunity Id of the record created in first step to opptyId;


so it would be

obj.opptyId = Opp Id of record created in first step.




    List<ProcessInstanceHistory> testList = obj.getApprovalSteps();

  System.assert(testList.size() > 0);



rekha sharmarekha sharma

Hi thanks for the reply,


I am stuck at the 2) ProcessSteps (Child) test data creation, if i will make this the line 8 will be covered in test class,(Attached snapshot)  please suggest 


As if now Test class is with 83% Coverage.



private class Test_OpportunityApprovalHistory {
       // Variable Declaration -------------------------------------------------------------------
             static Opportunity objOpportunity;

         static testMethod void myUnitTest() {
        //Test Data for Opportunity-----------------------------------------------------------------
             objOpportunity = new Opportunity();
             objOpportunity.StageName='Closed Won';
             insert objOpportunity;

      OpportunityApprovalHistoryController objOAC= new OpportunityApprovalHistoryController();