3

I want to created a component that would be used on a record detail page in a community
The component I created co far implements force:hasRecordId (and few more) but the id I get on run time in null.

flexipage:availableForRecordHome,
flexipage:availableForAllPageTypes,
force:hasRecordId,force:hasSObjectName,
forceCommunity:availableForAllPageTypes

What am I doing wrong. Is the feature only available for home pages?

2 Answers 2

5

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 
    
  }
})
7
  • unfortunately adding the entry in design and the default value didn't change anything. Console log still says "undefined":( My community in preview mode
    – user682217
    Commented Aug 18, 2016 at 13:20
  • 2
    Is it on the record detail ? .Also remember in builder parameter in admin mode you will manually input that variable as "{! recordId}" Commented Aug 18, 2016 at 13:28
  • Thank you!!! that did the trick - {! recordId} in the builder
    – user682217
    Commented Aug 18, 2016 at 13:34
  • the only thing that is still broken is that the response I print in callback is not set on the component fileAction.setCallback(this, function(response) { console.log(response.getReturnValue()); component.set("v.sFileName", response.getReturnValue()); }); I compared with examples on the web, checked for typos and I don't see why
    – user682217
    Commented Aug 18, 2016 at 13:45
  • that might be different one .Get the whole code in another thread so that can be worked Commented Aug 18, 2016 at 13:46
5

force:hasRecordId is supported in communities, you can reference it in your component markup as follows:

{!v.recordId}

or fetch it as if it were an attribute from your controller as follows:

component.get('v.recordId')

Quick note, it has to be used in an object detail or record detail page within communities.

3
  • As of December '18 this method works. No need to create a design file. Commented Dec 19, 2018 at 15:39
  • I dont believe a design file was ever required iirc
    – glls
    Commented Dec 19, 2018 at 15:40
  • Yeah... just putting this in there for future generations of devs that might try to use the other answer (by Mohith Shrivastava). Commented Dec 19, 2018 at 15:45

You must log in to answer this question.

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