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
Mona WesoMona Weso 

I am receiving a Cover Coverage Failure error (0%) when attempting to deploy my Apex Class, Test Class, and VisualForce Page. My code tested 100% coverage in Sandbox.

I am receiving a Cover Coverage Failure error (0%) when attempting to deploy my Apex Class, Test Class, and VisualForce Page to production.  My code tested 100% coverage in Sandbox.  The error is on testPageRef method.  The error I am receiving is "System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Source__c]: [Source__c] 
Stack Trace: Class.expressControllerTest.testPageRef: line 9, column 1."  Any help would be appreciated!

Here is my Test Class:
@isTest
public class expressControllerTest {

public static testMethod void testPageRef() {

    Account acc = new Account(Name='Abce');
    insert acc;
    Program__c prg = new Program__c(Account__c=acc.Id);
    insert prg;
    Payment_Schedule__c pa = new Payment_Schedule__c();
    // TODO: Populate required Opportunity fields here
    pa.Name='test sfdc';
    pa.Program_Master__c = prg.Id;
    insert pa;
    
    
    PageReference pref = Page.Payment_Schedules; 
    pref.getParameters().put('id', prg.id);
    ApexPages.StandardController sc= new ApexPages.StandardController(prg);
    expressController exp = new expressController(sc);
    System.assert(null == exp.newPayment_Schedule());    
    System.assertNotEquals(null, exp.getheaders());
    
    System.assertNotEquals(null, exp.getpaymentschedules());
    
    System.assertEquals(null, exp.saveChanges());
}
}
Here is my Controller:
public class expressController {
  
  // Constructor
 public expressController(ApexPages.StandardController controller) {
  this.prog = (Program__c)controller.getSubject();
     this.schedules = [ SELECT 
      ps.Date_Due__c, 
      ps.Amount_Due__c, ps.Descriptions__c, ps.Date_From__c, 
      ps.Date_To__c, ps.Paid__c, ps.Id, ps.CreatedById,
      ps.Program_Master__c FROM Payment_Schedule__c ps where ps.program_Master__c = :prog.id ];
 }
 
 // Action Method called from page button
 public pagereference saveChanges() { 
  upsert this.schedules;
  return null;
 }
 
 // Action Method called from page link
 public pagereference newPayment_Schedule() { 
  payment_schedule__c ps = new payment_schedule__c();
  ps.program_master__c =this.prog.id; 
  schedules.add(ps);
  return null;
 }
 
 // public Getter to provide table headers 
 public string[] getheaders() { return new string [] 
  {'Date Due','Amount Due','Descriptions', 'Date From',
   'Date To','Paid'} ; }
 
 // public Getter to list payment schedules
 public payment_schedule__c[] getpaymentschedules() { 
  return this.schedules; 
 } 
 
 // class variables
 Program__c prog;
 payment_schedule__c[] schedules; 
}


 
Best Answer chosen by Mona Weso
SalesFORCE_enFORCErSalesFORCE_enFORCEr
It seems Source__c is a required field on Program object and you are not populating it while creating a Program record.
Program__c prg = new Program__c(Account__c=acc.Id);

I don't know the type of Source__c field but you need to populate it while creating Program.

All Answers

SalesFORCE_enFORCErSalesFORCE_enFORCEr
It seems Source__c is a required field on Program object and you are not populating it while creating a Program record.
Program__c prg = new Program__c(Account__c=acc.Id);

I don't know the type of Source__c field but you need to populate it while creating Program.
This was selected as the best answer
Mona WesoMona Weso
So simple!  That was it.  I made source not required for that specific page layout and I was able to validate and deploy.  Thank you!