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
Anupama@28Anupama@28 

get community user info

Hi,

We have a requirement where we need to update the communty user contact details, Is there a way to get the logged in community user information either through lightning component or community builder page or site.com page etc....

I have tried the below

> Created a VF page to get current user information and related contact information
> Created site and given link to the above VF page
> Created a community builder page and given llink to the above site

Here, If i hardcode the contactId in VF page / apex then its working fine but our requirement is to get the current logged in community user info and then fetch his/her contactId.
When i run this as community user the first step i.e. fetching user details itself is failing. 

Please help me to get the requirement done
thanks in advance.

Thanks,
anupama
 
Best Answer chosen by Anupama@28
sfdcMonkey.comsfdcMonkey.com
hi anupama 
in your apex class you can get current login user contact info by using below code 
id userId = UserInfo.getUserId();
User u = [select id, contactId from User where id = : userId];
id getContactId = u.contactId;
system.debug('getContactId' + getContactId);
i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper soltuions for others
thanks 

http://sfdcmonkey.com  (http://sfdcmonkey.com )
 

All Answers

sfdcMonkey.comsfdcMonkey.com
hi anupama 
in your apex class you can get current login user contact info by using below code 
id userId = UserInfo.getUserId();
User u = [select id, contactId from User where id = : userId];
id getContactId = u.contactId;
system.debug('getContactId' + getContactId);
i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper soltuions for others
thanks 

http://sfdcmonkey.com  (http://sfdcmonkey.com )
 
This was selected as the best answer
Anupama@28Anupama@28
Hi,

thanks for replying,
It works for normal users, but my requirement is how do i get the user info for logged in community user.

thaknks,
Anupama
 
sfdcMonkey.comsfdcMonkey.com
hi ,
this above code work as well for the community user. when you log in with any contact to communities, at this time above code get the information for the login user not the for the normal user.
try it 
Anupama@28Anupama@28
Thanks Piyush_soni, Used the above apex controller and I have fetched the contact info from lightning component's controller and it worked for me
Shrinwanti RayShrinwanti Ray
hi,
Can you please help me with the code for this.Since i am trying to fetch contact name and show it in lightning component but it isnt showing up!!