Is there any way to pre-populate the current logged in user's contact in a lookup field in communities using LWC


<lightning-record-edit-form  object-api-name="CustomObj__c"> 
<lightning-input-field  field-name="CustomField__c"  onchange={nameHandler}


import { LightningElement, wire } from 'lwc';
import getUserInfo from '@salesforce/apex/UserDetails.getUserInfo';
import Id from '@salesforce/user/Id';

export default class LwcUserDetail extends LightningElement {

    @wire(getUserInfo, { userId: Id }) 

Currently I have implemented this but not sure how to proceed

  • Yes. What have you tried so far?
    – sfdcfox
    Jan 13 at 4:42
  • @sfdcfox updated the answer. I am not sure how to proceed
    – code234
    Jan 13 at 5:00

You need to call the wired apex code to get the user's contact Id, here is an example code.

public static Id getCommUserContactId(Id userId) {
    User u = [SELECT contactId FROM User WHERE id = :userId];
    return u.ContactId;
  • thanks @rahul also how can I also display the associated account related to the community user
    – code234
    Jan 13 at 8:47
  • @code234 You can query the related fields like Contact.AccountId in the same query. Jan 13 at 9:04

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.