You need to sign in to do that
Don't have an account?
Batmansfdc
How to write a test class for this? can some one please help
User u = [SELECT Id, Contact.AccountId FROM User WHERE Id = :UserInfo.getUserId()][0];
contact.AccountId = u.Contact.AccountId;
insert contact;
contact.AccountId = u.Contact.AccountId;
insert contact;
try this code .
user u1 = [select id,name from user where id = :UserInfo.getUserId() LIMIT 1];
system.runas(u1)
{
contact.AccountId = u1.Contact.AccountId;
insert contact;
}
I am getting below error message
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: User.Contact