2

I have an AuraComponent that wraps an lwc component for the purpose of using the workspace API. AuraComponent can see the recordId. In LWC component the recordId is always undefined. I have checked the meta-xml file. If I directly place myLWC2 in a page via App Builder, it renders {recordId}

What is missing/incorrect?

<aura:component implements="lightning:isUrlAddressable,flexipage:availableForAllPageTypes,force:hasRecordId" access="global">
    <lightning:workspaceAPI aura:id="workspace"/>

    <c:myLWC2 record-id="{!v.recordId}" onworkspaceAPI="{!c.handleWorkspaceAPI}"></c:myLWC2>

    RecordId: {!v.recordId}
</aura:component>

myLWC2.js-meta.xml:

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="myLWC2">
    <apiVersion>45.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
  </targets>
</LightningComponentBundle>

myLWC2.js:

import { LightningElement, track, api } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';

export default class myLWC2 extends NavigationMixin(LightningElement) {
    @api
    recordId;

}

myLWC2.html:

<template>
    RecordId: {recordId}
</template>
  • did you checked record-id in the lwc? – Vidhyasagaran Muralidharan May 27 '19 at 0:57
  • Answering my own post/question. It was an attribute naming problem: recordId="{!v.recordId}" – Mohammed Sheriff May 27 '19 at 0:59
3

Answering my own post/question. It was an attribute naming problem: recordId="{!v.recordId}"

Somewhere I have seen record-id was mentioned (in some documentation or sample about wrapping lwc components for workspaceAPI usage via Aura component) that made me provide the attribute to be record-id (and not recordId).

Hope this helps people to check all the conditions who had similar problems following that documentation or sample

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.