5

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">
    <apiVersion>45.0</apiVersion>
    <isExposed>true</isExposed>
    <masterLabel>ContractorSearch</masterLabel>
    <description>Searches for contractors for a given set of criteria</description>
    <targets>
        <target>lightning__RecordPage</target>
        <target>lightningCommunity__Page</target>
        <target>lightningCommunity__Default</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightning__RecordPage">
            <objects>
                <object>Requisition__c</object>
            </objects>
        </targetConfig>
        <targetConfig targets="lightningCommunity__Default">
            <property name="recordId" default="{!recordId}" type="String" 
                label="Record ID" description="Should not be changed from default value."/>
        </targetConfig>
    </targetConfigs>
</LightningComponentBundle>

Any ideas?

7

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}."/>

Update:

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

JS:

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 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 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 at 17:49
  • 1
    @gNerb I have done as you said but its not working for me – rahul gawale Sep 24 at 14:47

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.