0

I'm new with all of this so please be gentle :) So...I've got a lightning:recordForm that I'm using to create a new record. After I hit save I would like to be redirected to the newly created record.

Here's my cmp:

<aura:component controller="text_card_r" implements="force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
        <aura:attribute name="projects" type="List"/>   
        <aura:attribute name="employees" type="List"/>
        <aura:attribute name="employeesProjects" type="List"/>
        <aura:attribute name="isModalOpen" type="boolean" default="false"/>
        <lightning:notificationsLibrary aura:id="notifLib"/>
        <lightning:navigation aura:id="navService"/>    
        <!-- beginning card do header-->
        <lightning:card variant="Narrow" title="Projects Cards" iconName="standard:record" >
                <aura:set attribute="actions">
                    <lightning:button label="New" onclick="{! c.openModel }"/>
                </aura:set>            
        </lightning:card>        
      <!-- end card do header-->            

    <!-- beginning modal-->
    <div class="slds-m-around_xx-large">
        <!--Use aura:if tag to display/hide popup based on isModalOpen value-->  
        <aura:if isTrue="{!v.isModalOpen}">

            <!-- Modal/Popup Box starts here-->
            <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">
                <div class="slds-modal__container">
                    <!-- Modal/Popup Box Header Starts here-->
                    <header class="slds-modal__header">
                        <h3 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">New Project</h3>
                    </header>
                    <!--Modal/Popup Box Body Starts here-->
                    <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                        <lightning:recordForm

                            objectApiName="Project__c"                            
                            layoutType="Full" 
                            mode="edit"                             
                            onsuccess="{!c.handleSuccess}" 
                            oncancel="{!c.closeModel}"/>

                    </div>
                    <!--Modal/Popup Box Footer Starts here-->
                </div>
            </section>
            <div class="slds-backdrop slds-backdrop_open"></div>
        </aura:if>
    </div>

And here's my handleSuccess in the controller:

handleSuccess: function(component, event, helper) {
    var params = event.getParams();
    component.find("navService").navigate({
        "type": "standard__recordPage",
        "attributes": {
            "recordId": params.response.id,
            "objectApiName": "Project__c",
            "actionName": "view"
        }
    });
    component.set("v.isModalOpen", false);
}

Its not working. The record gets created but it prompts a popup message error instead of redirecting it to the new record.

[NoErrorObjectAvailable] Script error. a()@https://static.lightning.force.com/eu29/auraFW/javascript/5EkiQjrG-amda9Z1-HgsDQ/aura_prod.js:936:169 {anonymous}()@https://static.lightning.force.com/eu29/auraFW/javascript/5EkiQjrG-amda9Z1-HgsDQ/aura_prod.js:936:362 v.dispatchEvent()@https://static.lightning.force.com/eu29/auraFW/javascript/5EkiQjrG-amda9Z1-HgsDQ/aura_prod.js:4:25839 v.handleSuccess()@https://coee-management-dev-ed.lightning.force.com/components/lightning/recordForm.js:2:8296 o.createOrSaveRecord.then._pendingAction()@https://coee-management-dev-ed.lightning.force.com/components/interop/recordEditForm.js:2:7050

Could you please help me?

6
  • 1
    What error are you receiving?
    – Jayant Das
    Commented May 25, 2020 at 17:08
  • @JayantDas, check it out here: pastebin.com/4Dype622
    – Flemingpt
    Commented May 25, 2020 at 17:11
  • Can you edit your question to add that detail?
    – Jayant Das
    Commented May 25, 2020 at 17:13
  • Yep. Will do it.
    – Flemingpt
    Commented May 25, 2020 at 17:13
  • 1
    I think Jayant was asking you to provide the text of the error message here, on this site rather than keeping it as a link (which will eventually expire). The more hoops you make people jump through, even if they're easy, the less likely they are to help. Having the error message here also helps give context to the question so that other people with similar problems can say "hey, that looks like the problem I'm having, I wonder if one of the answers will help me".
    – Derek F
    Commented May 25, 2020 at 18:50

1 Answer 1

0

If You want to just redirect to particular record detail page then use below code

var navEvt = $A.get("e.force:navigateToSObject");
    navEvt.setParams({
      "recordId": "00QB0000000ybNX",
      "slideDevName": "Detail"
    });
    navEvt.fire();

Please refer https://developer.salesforce.com/docs/component-library/bundle/force:navigateToSObject/documentation

3
  • Thanks! And how can i get the recordId of the recently created object from the recordForm?
    – Flemingpt
    Commented May 26, 2020 at 8:33
  • Please use event.getParam("id") Commented May 26, 2020 at 9:57
  • handleSuccess : function (component, event, helper){ var payload = event.getParams("id"); var navEvt = $A.get("e.force:navigateToSObject"); navEvt.setParams({ "recordId": payload.id, "slideDevName": "Detail" }); navEvt.fire(); } it works!
    – Flemingpt
    Commented May 26, 2020 at 10:44

You must log in to answer this question.

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