I have created a component which is creating opportunity record and I want after successfull creation it redirects to the newly created opportunity detail page.

Opportunity creation is working fine but after creation it is not redirecting to the detail page. It throws the error

This page has an error. You might just need to refresh it. Error in $A.getCallback() [Cannot read property 'setParams' of undefined] Callback failed: apex://createOpp/ACTION$CreateOpportunity Failing descriptor: {c:createNewOppCmp}


save : function(component, event, helper) {
    var OpptyObj = component.get("v.Oppty");

    var action = component.get("c.CreateOpportunity");

        Oppty : OpptyObj 


        var oppId = res.getReturnValue();
          var urlEvent = $A.get("e.force:navigateToURL");
           //   "url": "https://ashuforce-dev-ed.my.salesforce.com/"+oppId+" "
                "url" : "/006/o"+oppId


} })

Not sure why e.force:navigateToURL is not working properly, what I am missing here?

  • apex controller returning the id of newly created record, I can see in the alert.
    – Ashutosh
    Jun 12, 2018 at 11:33
  • Nopes, that's the complete one which I am getting everytime.
    – Ashutosh
    Jun 12, 2018 at 11:36
  • if you completely remove the navigation event related code, do you still get the error?
    – glls
    Jun 12, 2018 at 11:38
  • No, if I remove then it works fine without any error.
    – Ashutosh
    Jun 12, 2018 at 11:39
  • alert(oppId); This part is working? So do you recieve oppId and alert shows it? Jun 12, 2018 at 12:14

2 Answers 2


Use new lightning:navigation component for that. Just add it to your component:

<lightning:navigation aura:id="navigation"/>

and in method navigate to detail page:

        "type" : "standard__recordPage",
        "attributes": {
            "recordId"      : recordId,
            "actionName"    : actionName ? actionName : "view"   //clone, edit, view
    }, true);

ps. you need to change API version to 43 in your component.


First of all: are you sure that you're recieving response with id of newly created opportunity?

I would recommend to check the state of the response before trying to navigate to created record, and then use e.force:navigateToSObject

var state = res.getState();
if(state === 'SUCCESS'){
    var oppId = res.getReturnValue();
    var navEvt = $A.get("e.force:navigateToSObject");
        "recordId": oppId
  • Yes, opportunity is creating successfully also I am getting the Id of the newly created opportunity record in the JS controller but getting the same error in navigating.
    – Ashutosh
    Jun 13, 2018 at 4:07
  • Could you please provide your apex backend code? From the description of the error I think something is wrong there and not in the navigation itself. Jun 13, 2018 at 7:50

You must log in to answer this question.

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