function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jose ZunigaJose Zuniga 

Getting Person account properties from a User

if I have a user that has "plugged" a person account throught 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 all the account properties from User?  Is there something like   U.ContactId__r.personemail? 

Thanks
 
NagendraNagendra (Salesforce Developers) 
Hi Jose,


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);
}
Please mark this post as solved if it helps.

Best Regards,
Nagendra.P