function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Phuc Nguyen 18Phuc Nguyen 18 

Aura component close after create record

Hello All,
I am using an aura compone to override a new button.  But the cancel does not have any effect and the window does not close after save.
If I stick the aura in a quick action it works but not when I use it to override the 'new' button.  Any thoughts? 
Best Answer chosen by Phuc Nguyen 18
David Zhu 🔥David Zhu 🔥
I would suggest call navigation service once the create record is done.

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

in js controller or helper after record is created:

component.find("navService") .navigate({
    "type" : "standard__recordPage",
    "attributes": { "recordId" : "001xxxxxxxxx",
          "objectApiName": "Account",
           "actionName": "view"
  } }, true);

You may get more details here: 
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_navigation_dfv.htm

All Answers

David Zhu 🔥David Zhu 🔥
You may add this line to close quick action.
$A.get("e.force:closeQuickAction").fire();
Phuc Nguyen 18Phuc Nguyen 18
Hey David,
This is not a quick action.  I am overriding the standard 'New' button so this opens a page and not a module.  Will this still work? Does your example go in the helper.js?
Thanks
David Zhu 🔥David Zhu 🔥
I would suggest call navigation service once the create record is done.

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

in js controller or helper after record is created:

component.find("navService") .navigate({
    "type" : "standard__recordPage",
    "attributes": { "recordId" : "001xxxxxxxxx",
          "objectApiName": "Account",
           "actionName": "view"
  } }, true);

You may get more details here: 
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_navigation_dfv.htm
This was selected as the best answer
mukesh guptamukesh gupta
Hi Phuc,

you cabn use on cancel button:-

  $A.get("e.force:closeQuickAction").fire();  

and make sure you are not implementing lightningQuickActionWithoutHeader  in component

If this solution is usefull for you, Please mark as a Best Answer to help others.


Regards
Mukesh

 
Jerome Mengullo 16Jerome Mengullo 16

I know this is already solved but I got here what worked for me:

In HTML:

<lightning:workspaceAPI aura:id="workspace"/>

 

In JS:

    var workspaceAPI = component.find("workspace");
    console.log('workspaceAPI =', workspaceAPI);
    workspaceAPI.getFocusedTabInfo()
    .then(function(response) {
        var focusedTabId = response.tabId;
        workspaceAPI.closeTab({tabId: focusedTabId});
    })
    .catch(function(error) {
        console.log(error);
    });

 

I hope this still helps people who will see this.