I'm trying to make a component in my community be able to pull in the record Id.

I followed the information in this question: LWC Community recordId undefined

And this documentation: https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.use_config_for_community_builder

My config file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <description>Searches for contractors for a given set of criteria</description>
        <targetConfig targets="lightning__RecordPage">
        <targetConfig targets="lightningCommunity__Default">
            <property name="recordId" default="{!recordId}" type="String" 
                label="Record ID" description="Should not be changed from default value."/>

Any ideas?


Apparently Salesforce is not clever enough to understand when you put in {!recordId} as a default value.

Removing the default value and setting the property in the community fixed the issue.

<property name="recordId" type="String" 
    label="Record ID" description="The value should be {!recordId}."/>


For people stumbling across this answer in the future, here is the full code of the component I made that is 100% functional.

Remember to set the variable in the component properties within your community:

enter image description here


import STATE_FIELD from '@salesforce/schema/Requisition__c.State__c';
//... for all fields

const requisitionFields = [
    STATE_FIELD, //... For all fields

@api recordId;
@track requisition;

@wire(getRecord, {recordId:'$recordId', fields:requisitionFields})
    getRequisition({error, data}) { 
        if(data) {
            this.requisition = data;

Update 2

A similar question was posted here. I have added another answer with copy/pasta code. The information is the same as what can be found in this answer and in the component I provided on github above; however, it is worded differently. If you are having issues with the answer above you can review the answer on the other question as well.

  • 1
    How did you access the recordId in the Js file? console.log(recordId); doesn't return anything.
    – cartman
    Jun 26 '19 at 12:57
  • I would recommend asking another question where you can provide samples of your code and more information. I will keep an eye out and try to help you when I see it.
    – gNerb
    Jun 26 '19 at 19:37
  • @cartman You should be able to access by setting @api recordId at the top of the class and this.recordId in the classes' methods but that doesn't seem to work for me.
    – Rozgonyi
    Sep 23 '19 at 17:49
  • 1
    @gNerb I have done as you said but its not working for me Sep 24 '19 at 14:47
  • Awesome, thanks. It was totally not something I would have guessed off hand. You saved me like an hour or two. It worked for me - just remove the default setting from the meta.xml file, and manually entered the record id in the component on the community page in builder. Sep 16 '20 at 23:22

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.