1

I have below component code to convert the name to hyperlink which will open up its' default record page component:

 <aura:component controller="RaceController">
    <aura:attribute name="race" type="Race__C" />
    <aura:attribute name="recordId" type="String" /> 
    <header class="slds-card__header" >               
        <p class="slds-text-heading--label" >

            <a onclick="{!c.handleClick}"> {!'RaceName: ' + v.race.Name} </a></p>
    </header>

controller:

handleClick : function (component, event, helper) {
        var navEvt = $A.get("e.force:navigateToSObject");
        navEvt.setParams({
            "recordId": component.get("v.recordId")
        });
        navEvt.fire();
    }

I want it to open the below page after clicking the hyperlink

enter image description here

but when I click on the hyperlink {!'RaceName: ' + v.race.Name} I get the below error

enter image description here

and after using the lightning app builder I am getting the below error enter image description here

18
  • is component.get("v.recordId") returning a value? doesnt look like it is (maybe im wrong)
    – glls
    Jul 11, 2018 at 17:43
  • navEvt appears to be coming back undefined. Are you running this component inside one.app, or using something like Lightning Out, which doesn't support that kind of event?
    – David Reed
    Jul 11, 2018 at 18:07
  • I think you are missing force:hasRecordId. You need to implement it to get the record Id. Jul 11, 2018 at 18:11
  • Do you want to alter standard lightning component? to convert Name field to hyperlink ? Jul 11, 2018 at 18:15
  • @DavidReed I have defined it in a component then iterating it in another component and finally wrote the component in an app and hitting the preview button
    – gs650x
    Jul 11, 2018 at 18:29

1 Answer 1

1

Try this? Opens in a new tab.

handleClick : function(component, event, helper){
        var recordId = component.get("v.recordId");
        window.open('/' + recordId);  
    },
3
  • Thank you so much for your response but I am using lightning and with the above code it opened up a new tab of classic with the message URL No Longer Exists
    – gs650x
    Jul 11, 2018 at 20:52
  • Perhaps there is a page override/redirect in place? Just open the record manually in a browser tab, see how your lightning URL looks like and adjust the string in window.open accordingly. Of course, this will come back biting you IF salesforce decides to change their URL construct. Happened in the recent past. Jul 11, 2018 at 21:02
  • I somehow solved the problem, but it works only on salesforce one app, not at the desktop version
    – gs650x
    Jul 12, 2018 at 14:05

You must log in to answer this question.

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