I have written a customer controller for a VisualForce page which displays all the Contact records associated with a particular Account. When manually testing the VisualForce page everything seems to work fine. All of the Contacts are displayed as I want them to be.
However, when I write some test code, my SELECT statement doesn't pull out my test Contact that I've associated with my test Account. I'm wondering whether it is to do with the way that I have written my SELECT statement.
My SELECT statement:
[SELECT Id, FirstName, LastName, Email, Salutation, Title, Primary__c, To_Be_Deleted__c FROM Contact WHERE Contact.Account.Id = :accountID AND To_Be_Deleted__c = false];
Some setup code in my test class:
Account acc = new Account(name = 'Test Account'); Contact validPrimaryContact = getValidActiveContact(); validPrimaryContact.Primary__c = true; validPrimaryContact.Account = acc; insert acc; insert validPrimaryContact;
Debugging Log showing that no rows have been found for that select statement:
16:00:36.448 (1448431000)|CONSTRUCTOR_ENTRY||01pP000000058yE|<init>(String,String) 16:00:36.448 (1448781000)|METHOD_ENTRY||01pP000000058yE|ContactCleanupController.init() 16:00:36.448 (1448858000)|USER_DEBUG||DEBUG|accountID: 001P000000Z1iPjIAJ 16:00:36.448 (1448901000)|USER_DEBUG||DEBUG|returnID: 001P000000Z1iPjIAJ 16:00:36.448 (1448925000)|METHOD_ENTRY||01pP000000058yE|ContactCleanupController.selectOnlyActiveContacts() 16:00:36.449 (1449424000)|SOQL_EXECUTE_BEGIN||Aggregations:0|select Id, FirstName, LastName, Email, Salutation, Title, Primary__c, To_Be_Deleted__c from Contact where (Contact.Account.Id = :tmpVar1 and To_Be_Deleted__c = false) 16:00:36.456 (1456474000)|SOQL_EXECUTE_END||Rows:0
Not sure what I'm doing wrong here. Is it something to do with