0
<aura:component controller="QuickContactController" implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId" >
    <ltng:require styles="{!$Resource.Lightning+'/assets/styles/salesforce-lightning-design-system.css'}"/>
   <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="account" type="Account"/>
    <aura:attribute name="newContact" type="Contact" default="{'sobjectType':'contact'}"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    ...

Controller :

({
    doInit : function(component, event, helper) 
    {
        // Prepare the action to load account record

        alert(component.get("v.recordId"));
    }
)}

I got null. I hit the url with the right account id https://instance/namespace/contactListApplication.app?ID=0017F000004PnrMQAS

I read article that it inject the current page id to the attribute recordId. But I got null. Any Idea ? what I am missing here ? Please help me.

1
  • Record Id Only visiable for a sObject type Eg. https://myapp--crm.lightning.force.com/one/one.app#/sObject/003W000000QzKjcIAF/view
    – Tariq
    Commented Jul 17, 2017 at 11:55

2 Answers 2

3

Record Id Only visiable for a sObject type Eg. https://myapp--crm.lightning.force.com/one/one.app#/sObject/‌​003W000000QzKjcIAF/v‌​iew

force:hasRecordId will not work for a standalone app. (.app)

You may integrate your component with Contact sObject using app builder in order to use RecordId

2
  • +10 @Tariq Thanks . it works fine with lightning:actionOverride interface.
    – bharath
    Commented Jul 17, 2017 at 13:22
  • @bharath Enjoy buddy
    – Tariq
    Commented Jul 18, 2017 at 19:07
1

You should use: ?recordId= instead of ?ID=. So here is your link: https://instance/namespace/contactListApplication.app?recordId=0017F000004PnrMQAS

Also here:

The force:hasRecordId interface does two things to a component that implements it. It adds an attribute named recordId to your component. This attribute is of type String, and its value is an 18-character Salesforce record ID, for example: 001xx000003DGSWAA4. If you added it yourself, the attribute definition would look like the following markup: <aura:attribute name="recordId" type="String" />

Note: If your component implements force:hasRecordId, you don’t need to add a recordId attribute to the component yourself. If you do add it, don’t change the access level or type of the attribute or the component will cause a runtime error.

So you should change recordId type definition.

2
  • I tried this also its null. Let me try with @Tariq way
    – bharath
    Commented Jul 17, 2017 at 12:11
  • In a question you are showing code from component, but what is your <aura:application /> definition?
    – Roman
    Commented Jul 17, 2017 at 12:15

You must log in to answer this question.

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