1

I am trying to show the classic URL in the Lightning page using the lightning component. But the record ID doesnt show up in the component. The component and controller is like below

Component

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
      <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
   
    This is the Classic URL of the record https://test.my.salesforce.com/{!v.myRecordID}   
    
</aura:component>

Controller

({
    doInit : function(cmp) {
        var xyz = cmp.get("v.recordId");
        cmp.set("v.myRecordID",xyz);
    }
})

When I try to add this component in the record page

enter image description here

Not sure what is missing here

4
  • How are you calling doInit method ? Commented Apr 19, 2020 at 15:42
  • @MohithShrivastava I thought doInit is called when the page is loaded
    – user81642
    Commented Apr 19, 2020 at 15:49
  • @MohithShrivastava I did add ` <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>` in to my component but it didnt help. I updated the component code
    – user81642
    Commented Apr 19, 2020 at 16:10
  • 1
    check my answer! Commented Apr 19, 2020 at 16:12

2 Answers 2

1

You will have to explicitly call the init handler and you do not have attribute defined

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
      <aura:attribute name="myRecordID" type="String"/>

  <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>


   This is the Classic URL of the record https://test.my.salesforce.com/{!v.myRecordID}   

</aura:component>

The JS controller is

({
   doInit: function(cmp) {
    var xyz = cmp.get("v.recordId");
    cmp.set("v.myRecordID",xyz);
   }
})

You can also omit the attribute and the method just use the below code

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >

  This is the Classic URL of the record 
   https://test.my.salesforce.com/{!v.recordId}   

</aura:component>
4

A simpler solution wouldn't require any JS actually as you would be able to access the recordId attribute simply like below:

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >

    This is the Classic URL of the record https://test.my.salesforce.com/{!v.recordId}   

</aura:component>

You must log in to answer this question.

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