I have a problem capturing the record id from a record page in communities.
I followed Get RecordId in LWC From Community Page intructions but it's not working for me and i saw that is not working for more people.
As my LWC contains a lot of content i created a simple LWC that shows only the Record ID
ShowRecordId LWC
HTML
<template>
<p>Record Id: {recordId}</p>
</template>
JS
import { LightningElement, api } from 'lwc';
export default class ShowRecordId extends LightningElement {
@api recordId;
}
META
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>58.0</apiVersion>
<isExposed>true</isExposed>
<masterLabel>Record Id</masterLabel>
<targets>
<target>lightning__RecordPage</target>
<target>lightningCommunity__Page</target>
<target>lightningCommunity__Default</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning__RecordPage">
<property name="recordId" type="String" label="Record ID" description="Should be set to {!recordId}"/>
</targetConfig>
<targetConfig targets="lightningCommunity__Default">
<property name="recordId" type="String" label="Record ID" description="Should be set to {!recordId}"/>
</targetConfig>
</targetConfigs>
</LightningComponentBundle>
Result
I access to the page customer following the url
I added in the record page a standard record component to show that this is capturing the recordId from the context
Also I have seen that before publish I see an error that the record id is not being shown.
Here I just duplicated the ShowRecordId component in the Record Page
Error: Experience Builder can't display this component because its record ID isn't well formed. In the Propery Editor,enter a well-formed ID in the Record Id field --- for example {!recordId}.
But in this case here I put {!recordId}
{!recordId}
instead of requiring the admin to set it manually. Please edit your question to show how the digital experience page's URL is configured. It should be something like/:recordId
which is then where the variable used in the expression gets its value - the actual URL reference to the ID gets put into the variable which is then passed to the component.