+ Start a Discussion
juppyjuppy 

How to pass record id to Lightning component on record detail page

Hi good people,
I'm building a Lightning Experience prototype for the desktop.
I have placed a Lightning component on the Opportunity detail page. This component will display the results of a server-side query that uses the Opportunity id (and other Opportunity data) as filters in the query.
The component is linked to an Apex class (controller="xxx") and implements force:recordTab.
How do I pass details of the Opportunity record through to the Apex class?
Thanks in advance!
Best Answer chosen by juppy
juppyjuppy
Hi Andrew,
yes, I did solve this:

To get a record Id you need to implement the force:hasRecordId interface.
 
One you have done this you can access the record id by:
 
{!v.recordId}
 
http://docs.releasenotes.salesforce.com/en-us/winter16/release-notes/rn_lightning_components.htm

All Answers

Andrew WolderAndrew Wolder
Did you figure this out?  I have been looking for exactly the same answer. but havent managed to find it - I need to pull the current opportunity id and use that in my component.
juppyjuppy
Hi Andrew,
yes, I did solve this:

To get a record Id you need to implement the force:hasRecordId interface.
 
One you have done this you can access the record id by:
 
{!v.recordId}
 
http://docs.releasenotes.salesforce.com/en-us/winter16/release-notes/rn_lightning_components.htm
This was selected as the best answer
Andrew JackmanAndrew Jackman
I am 100% sure this isn't working for me, and I cannot find the reason why.  I have a custom object I am trying to access the record ID from (if that matters).  Here is my component code:

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

A description of the set up. Using the Community Builder, I selected New Page > Data Detail Page > selected the object that I wanted > dragged my component onto the page.

My end goal is to create a styled details output, showing only a couple fields for a specific profile of users.
SBgooSBgoo
Hello Andrew, I have the same exact issue: I cannot access recordId in any way. Have you figured out anything?

Thanks
SBgooSBgoo
These are useful links to solve this issue, but I haven't been able to figure out how to make it work yet:
  • https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_config_for_app_builder_record_home_pilot.htm
  • https://developer.salesforce.com/page/Lightning_FAQ
  • http://salesforce.stackexchange.com/questions/93060/lightning-component-record-id-when-component-in-lightning-page
Could anyone understand if this impossibility to read the recordId of the current record from within a lightning component within a community based on templates is a limitation of the current implementation or if there is a way to have it work? I am using Winter '16.

Thanks!

   Sebastiano
SBgooSBgoo
Hello, I found the solution. It's published here:
https://success.salesforce.com/0D53000002PiTVf