Test data creation:
Account acct = new Account(Name='TestAccount', Field__c='TestInfo');
insert acct;
Contact con = new Contact(FirstName = 'TestFname1',LastName = 'TestLname1', Email = '[email protected]',
AccountId = acct.Id);
insert con;
Profile p = [SELECT Id FROM Profile WHERE Name = 'Custom Profile'];
User u = new User(/* Standard and Custom fields*/, ContactId = con.Id);
System.debug('user.contactId: ' +u.ContactId);
System.debug('user.con.FirstName: ' +u.Contact.FirstName);
I can able to get the ContactId, but not the FirstName. How to get the Firstname and other fields(User.Contact.Account.Name)?
I tried to query: Select Contact.FirstName from User
which is working as expected, but why I cannot get this in my test data?