4

I am trying to link a contact to a user object in test case. However, it seems that user.contact = contact doesn't work and user.contactId = contact.id will cause an error saying contactId field is not writable. Any suggestions?

  • are u trying to create community user? – anmrk Sep 22 '14 at 7:31
  • No, I am just getting the current user info from the database. But user info is able to be seen without using seealldata, but contacts are not. So I am linking the user to a new contact in my test case. – Lance Shi Sep 22 '14 at 7:34
  • you OWD for User must be Read Only, that's why you are seeing all the users. Also you can't change the Contact associated with an user object. See this thread for more information salesforce.stackexchange.com/questions/17102/… Instead of liking an existing user you could create a new user in the test class and associate that user with the contact. – anmrk Sep 22 '14 at 7:39
4

You can't change the Contact associated with an user object. See this thread for more information. Instead of liking an existing user you could create a new user in the test class and associate that user with the contact. See this thread for creating user in test class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.