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

  • How are you calling doInit method ? – Mohith Shrivastava Apr 19 at 15:42
  • @MohithShrivastava I thought doInit is called when the page is loaded – user81642 Apr 19 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 Apr 19 at 16:10
  • 1
    check my answer! – Mohith Shrivastava Apr 19 at 16:12
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>
| improve this answer | |
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>
| improve this answer | |

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.