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}" >  

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");  

        "recordId": cid,   
        "slideDevName": "detail"


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"

  • 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 – Dave Roberts Jul 23 '17 at 15:45

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


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.

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.