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"

  • 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
3

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

2

Got solution to this after struggling for quite a while. $A.get("e.force:navigateToSObject") returns when only invoked from Salesforce1/Lightning experince 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 experince . It ran successfully.

Hope that helps.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.