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?

5

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 

  }
})
  • 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}" – Mohith Shrivastava 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 – Mohith Shrivastava Aug 18 '16 at 13:46
2

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.

  • As of December '18 this method works. No need to create a design file. – AvailableName 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). – AvailableName 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.