I tried to get record id from the custom object "Categories__c" unfortunately it is not working. When I try the same with the custom recordId, it works. Can anyone help me to solve this issue?.

Here are my following codes: Categories.html

        <lightning-layout horizontal-align="spread" multiple-rows>
            <lightning-record-view-form record-id= {recordId} object-api-name="Categories__c">
                <p style="color:blue;">Categories</p>
                <div class="slds-box slds-theme\_default">
            <lightning-layout-item size= 6 >
                <lightning-output-field field-name="Consultant_Summary__c"></lightning-output-field> 
                <lightning-output-field field-name="Developer_Summary__c"></lightning-output-field> 
                <lightning-output-field field-name="Senior_Developer_Summary__c"></lightning-output-field> 
                <lightning-output-field field-name="Senior_Consultant_Summary__c"></lightning-output-field> 
                <lightning-output-field field-name="Personal_Manager_Summary__c"></lightning-output-field> 


import { LightningElement, wire, api } from 'lwc';
import CONSULTANT from '@salesforce/schema/Categories__c.Consultant_Summary__c';
import DEVELOPER from '@salesforce/schema/Categories__c.Developer_Summary__c';
import SENIOR_CONSULTANT from '@salesforce/schema/Categories__c.Senior_Consultant_Summary__c';
import SENIOR_DEVELOPER from '@salesforce/schema/Categories__c.Senior_Developer_Summary__c';
import PERSONAL_MANAGER from '@salesforce/schema/Categories__c.Personal_Manager_Summary__c';
import getcat from '@salesforce/apex/CategoriesController.getcat';

const COLUMNS = [
    { label: 'Consultant (No of Days Estimated)', fieldName: CONSULTANT.fieldApiName, type: 'number' },
    { label: 'Developer (No of Days Estimated)', fieldName: DEVELOPER.fieldApiName, type: 'number' },
    { label: 'Senior Consultant (No of Days Estimated)', fieldName: SENIOR_CONSULTANT.fieldApiName, type: 'number' },
    { label: 'Senior Developer (No of Days Estimated)', fieldName: SENIOR_DEVELOPER.fieldApiName, type: 'number' },
    { label: 'Personal Manager (No of Days Estimated)', fieldName: PERSONAL_MANAGER.fieldApiName, type: 'number' }
export default class Categories extends LightningElement {
    @api recordId;
    columns = COLUMNS;


<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">

Here is the output if I give an actual record id instead of the keyword, with manual record id

Here is the output when I actually use the keyword "recordId". enter image description here

  • there is a "space" after your property declaration in the template, make sure that there is none Ex. record-id={prop}
    – glls
    Commented Jan 21, 2022 at 12:57
  • It's still not working. Commented Jan 21, 2022 at 13:04
  • recordId will work on record pages, I dont think it works locally
    – glls
    Commented Jan 21, 2022 at 13:06
  • Yes, it works now. Can you make type it as an answer so that I can accept your answer?. Commented Jan 21, 2022 at 13:13
  • sure, done as requested.
    – glls
    Commented Jan 21, 2022 at 14:15

1 Answer 1


recordId does not work Locally, it will only work on record pages as documented:

Make a Component Aware of Its Record Context

IMPORTANT The recordId is set only when you place or invoke the component in an explicit record context. In all other cases, the recordId isn’t set, and your component can’t depend on it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .