Skip to main content
deleted 171 characters in body
Source Link
Mohith Shrivastava
  • 92k
  • 19
  • 161
  • 214

force:hasRecordId is meant only for the Lightning experience and App builder and not the community builderuse .force:hasRecordId as documented here

For the communityExperience builder the way I have managed to get the record idID is as below

Create a design file like below

<design:component>
   <design:attribute name="recordId" label="recordId" description="Salesforce Id of the record" />
 </design:component>

Create an attribute mapping to the design variable

<aura:component implements="forceCommunity:availableForAllPageTypes,forceflexipage:appHostableavailableForAllPageTypes,flexipageforce:availableForAllPageTypes">hasRecordId">

 <!--ATTRIBUTES DECLARATION -->

 <aura:attribute name="recordId" type="String" default="{!recordId}"/>
   <aura:handler name="init" value="{!this}" action="{!c.getrecord}" />
 </aura:component>

LetsLet's get the Id now in our JS controller

({
   getresults: function(component, event, helper) {
    console.log(component.get("v.recordId"));//print the Id 
    
  }
})

force:hasRecordId is meant only for the Lightning experience and App builder and not the community builder .

For the community builder the way I have managed to get the record id is as below

Create a design file like below

<design:component>
   <design:attribute name="recordId" label="recordId" description="Salesforce Id of the record" />
 </design:component>

Create an attribute mapping to the design variable

<aura:component implements="forceCommunity:availableForAllPageTypes,force:appHostable,flexipage:availableForAllPageTypes">

 <!--ATTRIBUTES DECLARATION -->

 <aura:attribute name="recordId" type="String" default="{!recordId}"/>
   <aura:handler name="init" value="{!this}" action="{!c.getrecord}" />
 </aura:component>

Lets get the Id now in our JS controller

({
   getresults: function(component, event, helper) {
    console.log(component.get("v.recordId"));//print the Id 
    
  }
})

use force:hasRecordId as documented here

For the Experience builder the way I have managed to get the record ID is as below

Create an attribute

<aura:component implements="forceCommunity:availableForAllPageTypes,flexipage:availableForAllPageTypes,force:hasRecordId">

 <!--ATTRIBUTES DECLARATION -->

 <aura:attribute name="recordId" type="String" default="{!recordId}"/>
   <aura:handler name="init" value="{!this}" action="{!c.getrecord}" />
 </aura:component>

Let's get the Id now in our JS controller

({
   getresults: function(component, event, helper) {
    console.log(component.get("v.recordId"));//print the Id 
    
  }
})
Source Link
Mohith Shrivastava
  • 92k
  • 19
  • 161
  • 214

force:hasRecordId is meant only for the Lightning experience and App builder and not the community builder .

For the community builder the way I have managed to get the record id is as below

Create a design file like below

<design:component>
   <design:attribute name="recordId" label="recordId" description="Salesforce Id of the record" />
 </design:component>

Create an attribute mapping to the design variable

<aura:component implements="forceCommunity:availableForAllPageTypes,force:appHostable,flexipage:availableForAllPageTypes">

 <!--ATTRIBUTES DECLARATION -->

 <aura:attribute name="recordId" type="String" default="{!recordId}"/>
   <aura:handler name="init" value="{!this}" action="{!c.getrecord}" />
 </aura:component>

Lets get the Id now in our JS controller

({
   getresults: function(component, event, helper) {
    console.log(component.get("v.recordId"));//print the Id 
    
  }
})