0

After saving contact details, record is saved but it's not redirecting to contact detail page.

<aura:component implements="force:appHostable" >
<aura:attribute name="recordId" type="String" />
<div class="slds-p-bottom_large slds-p-left_large" style="width:500px">
    <lightning:recordEditForm objectApiName="Contact">
        <lightning:messages />
        <lightning:inputField fieldName="FirstName" />
        <lightning:inputField fieldName="LastName" />
        <lightning:inputField fieldName="Birthdate" />
        <lightning:inputField fieldName="Phone" />
        <lightning:button aura:id="submit" type="submit" label="Save record" class="slds-m-top_medium" />
        </lightning:recordEditForm>
</div>  

2

That’s because you have to code the redirection using the onsuccess event. The default behaviour is , does nothing on save, you will have to retrieve the Id of the record from the response object and use it to redirect to the appropriate record detail page/view. The component documentation has several code snippets that will help you achieve the functionality.

0

After successfully editing/saving record you can handle on success event:

<aura:component implements="force:appHostable" >
<aura:attribute name="recordId" type="String" />
<div class="slds-p-bottom_large slds-p-left_large" style="width:500px">
    <lightning:recordEditForm 
        objectApiName="Contact"
        onsuccess="{!c.handleSuccess}">
        <lightning:messages />
        <lightning:inputField fieldName="FirstName" />
        <lightning:inputField fieldName="LastName" />
        <lightning:inputField fieldName="Birthdate" />
        <lightning:inputField fieldName="Phone" />
        <lightning:button aura:id="submit" type="submit" label="Save record" class="slds-m-top_medium" />
        </lightning:recordEditForm>
        <lightning:navigation aura:id="navService"/>
</div>  

In Controller:

({
    handleSuccess : function(component, event, helper) {
    var payload = event.getParams().response;
    var navService = component.find("navService");

    var pageReference = {
        type: 'standard__recordPage',
        attributes: {
            "recordId": payload.id,
            "objectApiName": "Contact",
            "actionName": "view"
        }
    }
    event.preventDefault();
    navService.navigate(pageReference);  
    }    
})

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.