How would you create a relatedList record and stay on the same page instead of redirecting to the newly created record?

the below code works fine but the problem is that it's redirecting.

here is my code:

createRecord : function (component, event, helper) {
    var createRecordEvent = $A.get("e.force:createRecord");
        "entityApiName": "Contact"

<div class="c-container">
            <aura:set attribute="actions">
                <lightning:button label="New" onclick="{!c.createRecord}"/>
            <aura:set attribute="title">
                <b><a class="slds-card__header-link" onclick="{!c.handleGotoRelatedList}">{!(v.sobjectLabelPlural) + ' (' + (v.numberOfRecordsForTitle) + ')'}</a></b>
            <aura:set attribute="footer">
                <aura:if isTrue="{!not(empty(v.records))}">  
                    <a onclick="{!c.handleGotoRelatedList}">View All</a>
            <aura:if isTrue="{!not(empty(v.records))}">    
                <p class="slds-p-horizontal_small">                  
                    <lightning:datatable class="related-list"
                                         columns="{! v.columnsWithActions }"
                                         data="{! v.records }"
                                         onrowaction="{! c.handleRowAction }"

2 Answers 2


By using "panelOnDestroyCallback" param we can control what happens when recordCreate success. We used it to refresh related list and navigation also stopped.

var createRecord = $A.get("e.force:createRecord");
createRecord.setParam("entityApiName", 'Contact');
createRecord.setParam("navigationLocation", "LOOKUP");
createRecord.setParam("panelOnDestroyCallback", function callbackWrapper() {
   // refresh related list 

P.S. - i am very new on stack so i am noob to explaning things.

  • I try to refresh the page by doing $A.get("e.force:refreshView").fire(); but it does not refreshing the page, any idea?
    – Nick
    Oct 25, 2021 at 22:12
  • 1
    Custom component doesn't catch standard event until you catch them specially. <aura:handler event="force:refreshView" action="{!c.doInit}"/> . But in your case you just need to refresh datatable list variable v.records. For that You can call same method which fetch records from apex server in panelOnDestroyCallback callback function. Thanks. Oct 26, 2021 at 3:49

There is no way to modify the behaviour of the force:createRecord event to prevent the redirection after creating the record.

You can achieve something like that by leveraging the lightning:recordForm component (https://developer.salesforce.com/docs/component-library/bundle/lightning:recordForm/specification). This component can be configured to show the exact form that you are using in the modal when using the force:createRecord event. You can use it to create the record and customize the after-creation logic.

I have included an example of this in your component (I have also modified a little bit the component just to make it compile as I don't have the rest of your logic). You can see how I use the "New" button to show the form. Also as an example, on the success event I'm calling a getRecords method that could just retrieve the records again so the related table is updated with the new value:

  getRecords: function (component, event, helper) {
    //Include here the logic for obtaining the records for the related list
    //Maybe also set the v.showContactForm attribute to false to hide the form after creating the Record

  showContactForm: function (component, event, helper) {
    component.set("v.showContactForm", true);

    <aura:set attribute="actions">
      <lightning:button label="New" onclick="{!c.showContactForm}" />
    <aura:set attribute="title">
        ><a class="slds-card__header-link" onclick="{!c.handleGotoRelatedList}"
          >{!(v.sobjectLabelPlural) + ' (' + (v.numberOfRecordsForTitle) +

    <aura:if isTrue="{!v.showContactForm}">

    <aura:set attribute="footer">
      <aura:if isTrue="{!not(empty(v.records))}">
        <p class="slds-p-horizontal_small">Something Here</p>

To improve the usability, you could include the lightning:recordForm inside a modal so it would resemble even more to what you achieve with the force:createRecord event.

You must log in to answer this question.

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