You need to sign in to do that
Don't have an account?

I can't create User's Account and can't get User.AccountId in Test Class
@isTest private class TestCtrTurnoverEntryCmp { @isTest static void testTurnoverEntry(){ UserRole portalRole = [Select Id From UserRole Where PortalType = 'None' Limit 1]; Profile profile1 = [Select Id from Profile where name = 'System Administrator']; User newUser = new User( UserRoleId = portalRole.Id, ProfileId = profile1.id, Username = 'test@managemall.com', email = 'test@managemall.com', emailencodingkey = 'UTF-8', localesidkey = 'en_US', languagelocalekey = 'en_US', timezonesidkey = 'America/Los_Angeles', alias ='nuser', lastname ='sahin' ); insert newUser; system.runAs(newUser) { System.debug('Current User: ' + UserInfo.getUserName()); Account acc = new Account(Name = 'portalAccount', OwnerId = newUser.Id); insert acc; Contact con = new Contact ( AccountId = acc.id, LastName = 'portalContact' ); insert con; User user2 = [SELECT AccountId FROM User WHERE Username =: UserInfo.getUserName()]; System.debug('user1: ' + user1.AccountId); // this return null Test.startTest(); ...... Test.stopTest(); } } }

AccountId will be null for Salesforce users. AccountId and ContactId are used for Customer Portal users.