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
    The answer in the related question still works and the id variable displays properly. Maybe you can post what you tried? – Eric Nov 21 '15 at 20:00
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.

protected by Community Jan 23 '17 at 19:48

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.