2

I am trying to use the "navigateToSObject" to redirect to the detail page. But the method $A.get("e.force:navigateToSObject") is always returning null. I dont have a namespace. SO this isn't namespace related issue I assume.

Here is the code of my component

<aura:component >
<aura:attribute name="contactName" type="String"></aura:attribute>
<aura:attribute name="lastName" type="String"></aura:attribute>
<aura:attribute name="cid" type="String"></aura:attribute>
<div onclick="{!c.navigateToRecord}" >  
    <h1>{!v.lastName}</h1>
    <h3>{!v.contactName}</h3>
    <h3>{!v.cid}</h3>
</div>
</aura:component>

Here is the code of my java-script controller

    ({
    navigateToRecord : function(component, event, helper){
        var cid=component.get("v.cid")
       console.log('inside navigateToRecord '+cid); 

    var navEvent = $A.get("e.force:navigateToSObject");  

    navEvent.setParams({
        "recordId": cid,   
        "slideDevName": "detail"
    });

    navEvent.fire(); 
}
})

I am getting null in navEvent hence am not able to set parameters into it. The error is "Uncaught error in $A.run() : Cannot read property 'setParams' of null"

1
  • In a similar situation, did the same: i.e. used the App Builder but also added <aura:component implements="force:appHostable,force:lightningQuickActionWithoutHeader,force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes"> to the component. and an aura:dependency tag. <aura:dependency resource="markup://force:navigateToSObject" type="EVENT"/> So works from an app but not from a web page ....lightning.force.com/c/MyApp.app
    – user45611
    Commented Jul 23, 2017 at 15:45

2 Answers 2

3

Yes, this event is supported in Salesforce1 only. If used outside of Salesforce1, this event won’t be handled properly.

3

Got the solution to this after struggling for quite a while. $A.get("e.force:navigateToSObject") returns when only invoked from Salesforce1/Lightning experience app. So while testing it directly(Without embodying it into Salesforce record home page ) it used to give null, cause there was no way to get e.force:navigateToSObject which is typical salesforce one event.

Solution: Made a lightning app using Lightning app builder, and ran my component from salesforce experience . It ran successfully.

Hope that helps.

You must log in to answer this question.

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