In the process of writing a unit test on Opportunities, I'm inserting a custom object Journal_c. This custom object, Journal_c, has an after insert trigger associated with it. When running the test, I encounter the following error.
FATAL_ERROR caused by: System.NullPointerException: Attempt to de-reference a null object.
Combing through logs, I've found the offending code to be a SOQL query (shown below) that is producing 0 results and thus the null object.
for ( Contact c : [Select Id, AccountId, Account.Id, Account.Anniversary_Date__c, Account.Member_Since__c, Account.Last_Membership_Date__c, Account.Total_Giving__c, Account.Total_Registration_Payments__c from Contact where Id in :allContactIds and AccountId != null ])
I have tried inserting a Journal__c record through the Salesforce interface and the insert was successful with the above query returning 1 row as a result. Inserting a record as a part of this unit test, however, produces 0 rows and cascades down to the error I mentioned. I have confirmed in both cases that allContactIds set contains a valid contact Id. In fact, it was the same contact Id. What could cause this query to produce different results?
