I am uploading the salesforce app on app exchange but while uploading it is showing error in test class but in the developer console it is running perfectly and it showing 87% code coverage Error is (Message)
System.DmlException: Upsert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [seit__Date_Created__c, seit__Agent_ID__c, seit__Customer_ID__c, seit__Property_ID__c]: [seit__Date_Created__c, seit__Agent_ID__c, seit__Customer_ID__c, seit__Property_ID__c]
My test method is given below
static testMethod void saveA1()
{
seit__Invoice_Table__c pro = new seit__Invoice_Table__c(seit__Date_Created__c=System.today(), seit__Agent_ID__c='a0161000004pUjR', seit__Customer_ID__c='a04610000030Nfp', seit__Property_ID__c='a0261000002iTPk',seit__Payment_Mode__c='Instalments', seit__Instalments__c='3');
ApexPages.StandardController sc = new ApexPages.standardController(pro);
InvoiceController controller = new InvoiceController(sc);
controller.SaveInvoice();
}
My controller is
public with sharing class InvoiceController {
public List<seit__Invoice_Table__c> getInvoice {get; set;}
public seit__Invoice_Table__c invoice {get; set;}
public string searchText {get;set;}
public List<seit__Invoice_Table__c> searchResults {get;set;}
public InvoiceController(ApexPages.StandardController controller) {
invoice=new seit__Invoice_Table__c();
getInvoice = [SELECT Id,Name,seit__Date_Created__c, seit__Agent_ID__c,seit__Agent_Name__c, seit__Discount__c,seit__Customer_Name__c, seit__Property_ID__c,seit__Property_Name__c,seit__Email__c,seit__Customer_Phone_Number__c,seit__Property_Address__c,seit__Property_Size__c,seit__Property_Size_sq_feet__c,seit__Price__c,seit__Agent_Phone_Number_del__c,seit__Payment_Mode__c,seit__Instalments__c,seit__Payment__c,seit__Customer_ID__c FROM seit__Invoice_Table__c];
}
public pageReference SaveInvoice()
{
try{
upsert invoice;
PageReference pageRef = new PageReference('https://itroos-dev-ed--seit.na34.visual.force.com/apex/InvoiceDetailImproveVFPage?core.apexpages.request.devconsole=1');
pageRef.setRedirect(true);
return pageRef;
}
catch(Exception ex)
{
ApexPages.addMessages(ex);
system.debug(ex);
PageReference pageRef = new PageReference('https://itroos-dev-ed--seit.na34.visual.force.com/apex/InvoiceDetailImproveVFPage?core.apexpages.request.devconsole=1');
pageRef.setRedirect(true);
throw ex;
}
}
}