jeudi 5 mai 2016

Salesforce Apex Test Class Failing on saving of an account

having a little trouble figuring out why my test class is returning System.DmlException: Upsert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Name]: [Name]

I have required field Name on the Account object in SFDC, but Since I'm mocking the Account with a Name attribute shouldn't my test class save function work?

Below is my Apex Class public with sharing class QuoteAccountController {

// Define VariableType and VariableName
public ApexPages.StandardController standardContactController;
public Account Account{get;set;}
public Contact Contact{get;set;}
public Account selectedAccount{get;set;}
public Boolean displayProjectInformation{get;set;}
public Boolean projectNameError{get;set;}
public Boolean projectValidationsPassed{get;set;}

//Page Constructor/Initializer
public QuoteAccountController(ApexPages.StandardController StandardController) {
    Account = new Account();    
    Contact = new Contact();
    displayProjectInformation = true;
    projectNameError = false;
    projectValidationsPassed = true;
}

public pageReference save() {
    projectValidations();
    if (projectValidationsPassed) {
        upsert Account;
        Contact.accountId = Account.id;
        upsert Contact;
        Contact = new Contact();
        Account = new Account();
        ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record Created Successfully.Thank you!'));
        return null;
     } else {
         return null;
     }
}    

Below is my Apex Test Class

@isTest
public class QuoteAccountControllerTest {
 private static testmethod void testSave() {
     Quote quote = new Quote();
     Account testAcc = new Account();
     Contact con = new Contact();
     ApexPages.StandardController stdCont = new ApexPages.StandardController(testAcc);
     QuoteAccountController quoteAccCont = new QuoteAccountController(stdCont);
     PageReference page = new PageReference('/apex/zqu_QuoteAccount?quoteType=Subscription&stepNumber=1');
     Test.setCurrentPage(page);

     testAcc.Project_Name__c = 'Project Name';
     testAcc.Name = 'Test Account';
     testAcc.Project_Start_Date__c = Date.today();
     testAcc.Project_End_Date__c = Date.today().addDays(2);
     testAcc.Project_Type__c =  'Convention Center';
     testAcc.Region__c = 'US';
     testAcc.Subscription_Type__c = 'User';

     Test.startTest();
     quoteAccCont.save();
     Test.stopTest();
 }
}

Thanks!

Aucun commentaire:

Enregistrer un commentaire