I am trying to create Lightning Code with will create an Account Record and navigate to its record detail page... However, I keep getting error as "Cannot Read property setParams of undefined"

Updated comp.cmp

<aura:dependency resource="markup://force:navigateToSObject" type="EVENT"/>

<aura:attribute name="myObj" type="Account" default="{'SObject':'Account'}"/>

<div class="slds-page-header">
    Account entry form...

<lightning:input type="text" name="accountName" label="Enter Account Name" value="{!v.myObj.Name}"/>
<lightning:input type="text" name="accountPhn" label="Enter Account Phone" value="{!v.myObj.Phone}"/>
<lightning:button label="Save" onclick="{!c.saveAcc}"/>

<!-- <c:comp2EventBased/> -->

Updated comp.js:

({ tstEvt : function(component, event, helper) { var evt = event.getParam("evt"); alert(":: Event Val :: "+evt); },

saveAcc : function(component, event, helper) {
    var obj = component.get("v.myObj");
    var action = component.get("c.createAcc");

    action.setCallback(this, function(acnt){            
        var state = action.getState(acnt);
        if (state == "SUCCESS") {
            var accID = acnt.getReturnValue();
            alert(":: Newly Created Account ID is :: "+accID);
            var navEvt = $A.get("e.force:navigateToSObject");
                "slideDevName": "related"



public class saveAndReturnAcc {

    public static Id createAcc(Account myObj){

        insert myObj;
        return myObj.Id;


Important to note that as soon as I remove the below redirection, it works fine:

var navLink = component.find("navLink");
                var pageRef = {
                    type: 'standard__recordPage',
                    attributes: {
                        actionName: 'view',
                        objectApiName: 'Account',
                        recordId : accID

Stuck for a while here... Appreciate help.

  • Why you are not using Lightning Data Service? – sanket kumar May 2 '19 at 11:20
  • Hello Sanket, Sorry I am new to Lightning Development... Hence don't know much about it. Will read about it for sure. – Varun SFDC May 2 '19 at 11:42

Did you try to use "force:navigateToSObject":

createRecord : function (component, event, helper) {
    var navEvt = $A.get("e.force:navigateToSObject");
      "recordId": "00QB0000000ybNX",
      "slideDevName": "related"
  • Hello Mo Hamada, Tried it... Unfortunately it doesn't give any error but doesn't redirect either. – Varun SFDC May 2 '19 at 9:29
  • The only reason for this, is that maybe your browser is blocking the pop ups. enable them and try it again – Mo Hamada May 2 '19 at 9:31
  • No Popup Blocker(Popups and Redirects are allowed)... but it just alerts for this alert(":: Newly Created Account ID is :: "+accID);) and nothing happens – Varun SFDC May 2 '19 at 9:39
  • alerts for this? what do you mean? – Mo Hamada May 2 '19 at 9:41
  • I have editted my comment – Varun SFDC May 2 '19 at 9:41

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.