I am trying to create a new record using a save button on a lightning:recordEditForm

Im am fairly new to coding lightning components and have come to a bit of a standstill trying to get it to redirect to the record it is creating.

I have managed to get it to redirect to the object home but using component.get("recordId") leads to a error page doesnt exist error and tells me to input a valid url.

Here is part of my component and my controller:

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId,force:lightningQuickActionWithoutHeader,flexipage:availableForRecordHome,lightning:actionOverride" 
            access="global" >

<aura:attribute name="recordId" type="Id"/>

<lightning:recordEditForm objectApiName="Factfind__c"
    <lightning:messages />

and here is my controller

handleSubmit : function(component, event, helper) {
    console.log("this is a test");
    //Display toast message
    var toastEvent = $A.get("e.force:showToast");
        "title": "Success!",
        "message": "Factfind has been created.",
        "type": "success"

    // Close Quick Action Panel:
    var dismissActionPanel = $A.get("e.force:closeQuickAction");
    var homeEvent = $A.get("e.force:navigateToSObject");
        "recordId": component.get("v.recordId")



Could someone please try and show me where i'm going wrong :)


The recordId you are using should come from lightning context if record already exists. But here you are creating new record - so you need to get the new record Id in onsuccess handler method.

Also, for navigation it is recommended to use navigation library with appropriate pageReference type

In cmp:

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

Then in onsuccess handler:

handleSuccess: function(cmp, event, helper) {
    var params = event.getParams();
        "type": "standard__recordPage",
        "attributes": {
            "recordId": params.response.id,
            "objectApiName": "Factfind__c",
            "actionName": "view"
  • 1
    Thankyou mate, fixed my issue so quickly!
    – JackDower
    Aug 15 '19 at 10:11

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.