6

I tried following the question and answer to no success here: Lightning Component record ID when component in Lightning Page

How can I access the record ID from the URL in a custom lightning component? My end goal is to create a styled object details component showing some of the information (instead of the default details component).

Here is the code I have used so far:

<aura:component controller="CommunityPost_Controller" implements="forceCommunity:availableForAllPageTypes,force:hasRecordId,force:recordTab">
    <aura:attribute name="Community_News_Item__c" type="Community_News_Item__c" />
    <ui:outputText class="form-control" aura:id="recid" value="{!v.recordId}" />
</aura:component>

And I am loading this off of a data detail page on a salesforce community with the Napili template enabled.

1
  • 1
    The answer in the related question still works and the id variable displays properly. Maybe you can post what you tried?
    – Eric
    Nov 21, 2015 at 20:00

1 Answer 1

9

I have finally figured it out. The force:hasRecordId is not available with Salesforce Communities. To access the record Id from a data detail page, you need to do two things:

  1. Create an aura attribute to hold the variable, and ensure you don't include a default value here

  2. Create a design attribute with a default value of {!recordId}

And that will allow the system to pass the record ID to the component when it loads on the page.

You must log in to answer this question.

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