+ Start a Discussion
amyer2240amyer2240 

Required Field Missing in test class

I'm getting the below error on my test class, which is failing:

-------

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, cv.AccountAll: execution of BeforeInsert

caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, SpaceAssignment: execution of AfterInsert

caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [aba__Space__c]: [aba__Space__c]

Trigger.SpaceAssignment: line 18, column 1: []

---------

Here is my quick scenario: I've written two simple triggers which work fine that create a junction object after insert of a contact or account; that junction object is linked to a Space (so after the trigger, all contacts/accounts are linked to Spaces via the junction object). This is all being done with objects in a managed package. My test class kept failing, so I entered the below as my test class. I'd understand if it didn't cover any of the code, but why would it fail?

@isTest 
private class SpaceUpdateTestClass {
static testMethod void testAccount() {
   
Account acc = new Account(Name = 'Test Account');
insert acc;

List <aba__Space_Account__c> spaceacc = [Select Id, Name, aba__Account__c from aba__Space_Account__c where aba__Account__c =:acc.Id];

System.assertEquals(spaceacc[0].aba__Account__c, acc.Id);
}}

Any guidance is appreciated!! Thank you!
Best Answer chosen by amyer2240
amyer2240amyer2240
Figured it out - needed SeeAllData=true