1

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? 

4
  • Are you trying to retrieve them or set them?
    – Adrian Larson
    Sep 28, 2016 at 3:47
  • no, no, ... I want to be able to retrieve any of the person account properties from the User object
    – Jose
    Sep 28, 2016 at 3:48
  • Is it a community user ? In case of community every contact will have a user record ? Sep 28, 2016 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
    Sep 28, 2016 at 3:54

1 Answer 1

0

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()){
     mapContactIdByUser.put(u.contactId,u);
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .