0

I create this controller to diplay on a visualforce page a custom approval related list of record with the signature (photo) of Actor for an object Called Car_Maintenance. It works perfectly on my sandbox but i have trouble to write the test Class to deploy it in the production.

The Controller and my test class are below. My headache start at the line 53 in the Test Class. the error message is some field are required in the approval record.

Controller


    public MaintenanceRequestController() {

    }


    public Map<Id,User> userMap { get; set; }
    public List<ProcessInstanceStep> processInstanceList { get; set; }

    public MaintenanceRequestController(ApexPages.StandardController controller) {
      userMap = new Map<Id, User>();
      processInstanceList = new List<ProcessInstanceStep>();
      Id recordId = ApexPages.CurrentPage().getparameters().get('id');
  
      processInstanceList = [Select id,ActorId, Actor.Name,CreatedDate, Actor.Title, Actor.FirstName , ProcessInstanceId, 
                              Actor.LastName, StepStatus, ProcessInstance.TargetObjectId
                              from ProcessInstanceStep
                              WHERE ProcessInstance.TargetObjectId = :recordId];
       for (ProcessInstanceStep step : processInstanceList){
            userMap.put(step.ActorId, new User(Signature__c=null));
       }
        userMap.putAll([SELECT Id,Name,Signature__c FROM User WHERE Id = :userMap.keySet()]);
    
        }

}```

test Class 

```@IsTest
public class CarMaitenanceControllerTest{
static testMethod  void CarMaitenanceController(){
   
     Car__c veh = new Car__c (  Category__c='Pickup', Color__c='Red', Condition__c='Excellent', 
     Description__c='Test Vehicle',  Engine_Number__c='XXX',
     Matriculation__c = 'IT-00011', Make__c='Toyota', Year__c ='2017', Model__c='Colorado');
          insert veh;
    
    
    Part_Accessories_Reception__c par = new Part_Accessories_Reception__c();
    par.Date__c = System.today();
    par.Provider__c = 'Other';
    
     
    insert par;
    
    Part_Accessories__c pa = new Part_Accessories__c(Name = 'filter');
    insert pa;
    
    
    Part_Accessories_Inventory__c pai =  new Part_Accessories_Inventory__c();
    pai.Quantity_Received__c =7771;
   
    pai.Part_Accessories_Reception__c = par.ID;
    pai.Part_Accessories__c = pa.Id;
    
    insert pai; 
    
    
    
    
     Car_Maintenance__c carMain = new Car_Maintenance__c();
       
          carMain.Car__c = veh.ID;
          carMain.Cheque_Bank__c = '444-Cmmm'; 
          carMain.Company__c = 'FFP';
          carMain.Date__c = System.today();

         insert carMain;
     
        Maintenance_Details__c mdet = new Maintenance_Details__c();
        mdet.Description__c      = 'qiuyiuyi';
        mdet.Quantity__c         =555;
        
        mdet.Maintenance__c      = carMain.Id;
        mdet.Description__c      ='kjalhsdhfklasdf';
        mdet.Cost__c             = 999;
        mdet.Part_Accessories_Inventory__c = pai.Id;

        insert mdet;
        
        Approval.ProcessSubmitRequest app = new Approval.ProcessSubmitRequest();
        app.setObjectId(carMain.Id);
        Approval.ProcessResult result = Approval.process(app);
        
        
        ProcessInstance pi = new ProcessInstance ();
        pi.TargetObjectId = carMain.Id;
        pi.Status ='Approved';
        Insert pi;
        
        ProcessInstanceStep pis = new ProcessInstanceStep();
        pis.ProcessInstanceId = pi.Id;
        Insert pis;

    Test.setCurrentPageReference(new PageReference('CarMaintenanceView')); 
    System.currentPageReference().getParameters().put('id', veh.ID);
    CarMaintenanceController CRC = new CarMaintenanceController();
    MaintenanceRequestController mrc = new MaintenanceRequestController();
    
}

}```
gbij
  • 1
  • 2

1 Answers1

0

Can you identify which is line 53 of the test class, the one that is giving you trouble? And the specific error?

It may be that the required fields in production are different than what's in the sandbox, and that's tripping you up when you insert your test data.

  • I am unable to save the test Class but i need help to increase the coverage, Actually it is 8%. – gbij Jul 19 '21 at 19:13