I have a lightning component that allows you to create a contact record via:

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

After I add the new contact in the popup I am navigated away from my current page and brought the view contact page. Is there any way to prevent this and remain on the current page? And, if so, is there a callback so that I know the save happened and I can reload related data on my page?


Yes, but you have to go the custom route. force:recordData and lightning:recordEditForm are yours friends. Here are a couple examples: Creating a Record, Lightning Data Service Example

  • In Summer 18 there is link which make form creation even easier. However, one of our requirements is the ability to set defaults on the form based on values in our component (i.e. we want to relate the object we are creating in the form to something in our component). I don't see any way to do this with lightning:recordForm though
    – Homerlex
    Jul 25 '18 at 13:25

As far as I can tell, there's no out of the box way to do this when using force:createRecord event. Using this event opens up the standard record create layout and that you don't have a way to capture the results after the record has been saved. The below excerpt from the documentation may help.

This event presents a standard page to create a record. That is, it doesn’t respect overrides on the object’s create action.

For your use case, the only route you have is to build a custom screen and save logic (using other available components and events) and accordingly utilize that for your needs.

Not the answer you're looking for? Browse other questions tagged or ask your own question.