7

Ok, stupid question but I have searched and could not find this anywhere...

Q: How to you get (what is the expression syntax of) the ID of the record which is displaying the component / app?

I have read that I need to implement the interface force:recordTab here

Q: How is Lightning aware of what record you are on if you embed it in Salesforce1? (i.e. how do you get the ID of the record you are on like in a standard controller)?

A: Your component just needs to implement the force:recordTab interface and the record and recordId will be automatically injected when your component is wired into record home.

from the FAQ: https://developer.salesforce.com/page/Lightning_FAQ

Since found to be incorrect (see answer)

but beyond that I could find no documentation on this interface or anything in the lightning component developer guide that discusses this.

Basically, on init I need to grab the ID of the record whose detail page is being displayed.

Sorry for the newbie question but you would think something this simple would be out there in the open.....

  • Can you do this on load of Lightning component and get Id in Controller constructor? I can pass it on button click and stuff. But can we get the id directly on load of page in constructor? – Kaushik Ray Jun 8 '16 at 9:46
  • It is available as a merge variable anywhere in the component – Eric Jun 8 '16 at 13:12
9

Ok, I found it after doing some serious reading of the Winter '16 release.

You need to implement the interface:

force:hasRecordId

in your component and then you can access the record id via the following expression

{!v.recordId}

An example component would be:

<aura:component controller="CTRL_F_Controller" implements="flexipage:availableForAllPageTypes,force:hasRecordId">
<aura:attribute name="Account" type="Account"/>
    <ltng:require styles="/resource/bootstrap"/>
    <div class="bootstrap-sf1">
       <div class="container">
           <ui:outputText class="form-control" aura:id="recid" value="{!v.recordId}" />
        </div>
    </div>
</aura:component>
  • I guess this is available only in winter 16 ?Does it work in summer 15 as well? – Mohith Shrivastava Sep 21 '15 at 2:24
  • I believe it is new for winter 16. Not sure how it is done in summer 15 or if it can be – Eric Sep 21 '15 at 2:26
  • It was not possible as straight as that :)..Thanks that we have and +1 from me on question and answer as well – Mohith Shrivastava Sep 21 '15 at 2:30
  • @MohithShrivastava - Would be interested in how you did it in Winter 15. Please feel free to update my answer with the code used from Winter 15 to accomplish this. – Eric Sep 21 '15 at 4:35
  • Are you embedding this component in any record detail page ? – Monish Oct 26 '15 at 5:47

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.