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.


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


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:attribute name="recordId" label="recordId" description="Salesforce Id of the record" />

Create an attribute mapping to the design variable

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


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

Lets get the Id now in our JS controller

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

  • 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
    Aug 18 '16 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}" Aug 18 '16 at 13:28
  • Thank you!!! that did the trick - {! recordId} in the builder
    – user682217
    Aug 18 '16 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
    Aug 18 '16 at 13:45
  • that might be different one .Get the whole code in another thread so that can be worked Aug 18 '16 at 13:46

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


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


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

  • As of December '18 this method works. No need to create a design file. Dec 19 '18 at 15:39
  • I dont believe a design file was ever required iirc
    – glls
    Dec 19 '18 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). Dec 19 '18 at 15:45

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.