You need to sign in to do that
Don't have an account?
Testing with user specific Account info
Id currentAccountId = uList.isEmpty() ? null : uList[0].contact.accountId;
But this doesn't seem to work in the test code. The UserInfo returns null. I know I can create a user and use System.RunAs() to run the test in context of that user, but my code to set the Contact AccountId for that test user is not working. Seems like there should be a better way of doing this.
Account acc = new Account(name='Test College',recordTypeId=AccountRecordTypeInfo .get('College/University').getRecordTypeId());
insert acc;
Profile p = [SELECT Id FROM Profile WHERE Name='College - FA&CC Combined'];
User u = new User(Alias = 'standt', Email='standarduser@testorg.com',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Denver', UserName='standarduser@testorg.com');
List<Contact> conList = [Select Id, AccountId from Contact Where Id = :u.ContactId ];
Contact con1 = conList.isEmpty() ? null : conList[0];
con1.AccountId = acc.Id;
So the goal is to have the current user's Contact entry list the test Account value created. Right now this is not working as the assignment (con1.AccountId = acc.Id) is coming back with "System.NullPointerException: Attempt to de-reference a null object"
Any ideas?
All Answers
Is there a custom user field on contact?