if I have a user that has "plugged" a person account through the User.ContactId,

Account a = handleAccount(create, u, attributes);    // a    gets an account object       
Id accountId = a.Id;     
User U  ....        
U.ContactId = [select PersonContactId  FROM account where ID =: accountId].PersonContactId; 

How can I do to refer to any of the person account properties from User?

Is there something like U.ContactId__r.personemail? 

  • Are you trying to retrieve them or set them? – Adrian Larson Sep 28 '16 at 3:47
  • no, no, ... I want to be able to retrieve any of the person account properties from the User object – Jose Cabrera Zuniga Sep 28 '16 at 3:48
  • Is it a community user ? In case of community every contact will have a user record ? – Mohith Shrivastava Sep 28 '16 at 3:48
  • Yes, we use communities. In many cases, for a User U we created a unique account A that become a person account (we use person accounts). Through the U.ContactId we plugged that account A to the user U. Now, I need to know how to use any of the fields of A from U. – Jose Cabrera Zuniga Sep 28 '16 at 3:54

Since the ContactID is not a true reference ,you will have to query the information back for users

map<Id,user> mapIdByuser = new map<Id,User>([Select Id,email from User where ContactId in :setContacts]);
map<Id,User> mapContactIdByUser = new map<Id,User>();
for(User u :mapIdByuser.values()){
| improve this answer | |

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.