+ Start a Discussion
Chaim Rosenfeld 8Chaim Rosenfeld 8 

apex test class giving 88% coverage but not being deployed

hello , my test class for this controller is giving 88% coverage, but it is not being deployed , can any one help me in this

public class addJobCntrl {

Public string leadID{get;set;}
Public Lead leadIns{get;set;}
Public Job__c jobIns{get;set;}
Public Job__c testjobIns{get;set;}

public addJobCntrl (){

leadID = apexpages.currentpage().getparameters().get('id');
leadIns= [select id, Company, State__c, Street__c , Zip__c , City__c , Type_of_Service_Proposal__c , Name  , Sales_Person__c, Insurance_Amount__c , Email, Credit_Application_received__c, Credit_Limit_Amount__c,  Phone from Lead where ID =: leadID ];
jobIns = new Job__c(Lead__c = leadID );


Public PageReference creatContract(){

jobIns.Name = leadIns.Company;
jobIns.Street__c = leadIns.Street__c ;
jobIns.State__c = leadIns.State__c ;
jobIns.Zipcode__c = leadIns.Zip__c ;
jobIns.City__c = leadIns.City__c ;
jobIns.Service_Type__c = leadIns.Type_of_Service_Proposal__c ;
jobIns.Billing_Contact__c = leadIns.Name  ;
jobIns.Billing_Email__c = leadIns.Email;
jobIns.Billing_Phone_Number__c =  leadIns.Phone;
jobIns.Credit_Application_received__c = leadIns.Credit_Application_received__c;
jobIns.Credit_Amount_Limit__c = leadIns.Credit_Limit_Amount__c;
jobIns.Insurance_Amount__c = leadIns.Insurance_Amount__c;
jobIns.Sales_Rep__c = leadIns.Sales_Person__c;

upsert jobIns;

PageReference p = new PageReference('/' + this.jobIns.Id );
return p;

this is Test class 

public class addJobCntrlTest{

static testMethod void testMethod1() {
       Account custIns = new Account();
       custIns.Name = 'test';
       custIns.QB_Company__c = 'qfs';
       custIns.QB_Account__c = 'test'; 
       custIns.Service_Type__c  = 'Mid-Construction';
       insert custIns;
       Job__c jobIns = new Job__c();
       jobIns.Name = 'test';
       jobIns.Sales_Rep__c = 'Aharon Kaplan';
       jobIns.Customer__c = custIns.ID;
       jobIns.Billing_Contact__c = 'test';  
       jobIns.Billing_Email__c= 'test@test.com'; 
       jobIns.Billing_Phone_Number__c= '123'; 
       jobIns.QB_Job_Name__c = 'test';   
       jobIns.QB_Company__c = 'QFS';
       insert jobIns;
       Lead testRecord= new Lead();
       testRecord.LastName = 'test name ';
       testRecord.Company = 'test company';
       testRecord.Status = 'new';
       testRecord.Credit_Limit_Amount__c = 12344;
       insert testRecord;

        System.currentPageReference().getParameters().put('id', testRecord.Id);

        addJobCntrl addjobCntrlTestIns = new addJobCntrl();

and this is error i keep getting from test run 

upsert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Customer__c]: 

Hi Chaim,

Please add the lookup field explicitly into the change set and deploy, even if its already present in the destination org.

Krishna Avva
Chaim Rosenfeld 8Chaim Rosenfeld 8
can you please elaborate , i didnt get it , your anser 
Hi Chaim,

When you deploy this change set, you will add the related classes and test classes too. Along with that, add the field Customer__c to the change set. Even though its already present in the destination org or nothing changed on that field.
Hopefully, it should solve your problem.

Krishna Avva