I have a code that is testing a batch, I am creating a contact and an Account , but the contact isn't getting linked to the account (c.AccountId = null). The same code is tested in Async window and it is creating a contact linked to an account.
Account account = new Account();
account.RecordType = AccountUtilities.RecordTypes.get('Corporate_Golden_Record');
account.Name = 'test corp';
account.phone= '01123123';
account.billingcity='London';
account.billingpostalcode='SW1635HJ';
account.billingcountry='United Kingdom';
account.billingstreet='address 1';
account.retailer_email__c= '[email protected]';
insert account;
//Insert contact for Account
Contact c = new Contact();
c.AccountId = account.ID;
c.FirstName = 'test';
c.LastName = 'test';
c.email = '[email protected]';
c.RecordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('Contact').getRecordTypeId();
c.Language__c = 'EN';
c.birthdate = Date.newInstance(1992, 04, 12);
insert c;
system.debug('-- Contact : ' + c.Account.Name);
system.debug('-- Contact : ' + c.ID);
Test.startTest();
...
Test.stopTest();