I'm new to Salesforce lightning. I'm trying to build a quick action that performs backend logic based on a condition else display a toast. I have created the component and associated it to an object based quick action. Now, after invoking the toast event, I'm trying to close the quickAction modal popup using $A.get("e.force:closeQuickAction").fire(); This doesn't seem to work.

So, I have removed the controller logic and just added that one line and it still doesn't work.

    doInit : function(component, event, helper) {

Requesting to guide me on this. Thanks!

  • Please be more elaborate on your doubt. doInit is something that runs on Load of a lightning component / action. Once you open a modal , you might need to close it using quick action.
    – AjaySFDC
    Aug 21 '17 at 0:56

The reason why it is working when invoked in callback code because there is modal listener ready for the event and then modal listener can close the model.

But if you write your logic on doInit ( I assume you are registering with init event) then there is no modal which is listening. So modal will not be able to close.

If I am not wrong here you want to run some apex logic and not show modal to user since you don't have anything to show to user.

I would suggest show the modal with some message saying that "YOUR XYZ OPERATION is in progress."

As the modal is completely loaded you can fire close event upon which modal will get closed.

Note: You can destroy the component in doInit but it will only destroy contents of modal not the component, so its better to go with the solution where you can let user know some action is going on.

Another Update (Date : Aug 2019) If you are required to close the modal in init without making any server call then you can simulate async call nature by

           let quickActionClose = $A.get("e.force:closeQuickAction");

This will make sure that component is loaded and ready to listen for close event.


Here is an example that i did for closeQuickAction to fire.

You need to add the lightning component as a quick action first and then include the same action on the lightning page layout.

js controller:

    doInit : function(component, event, helper) {

        var action = component.get("c.getRecordUpdate");

        action.setCallback(this, function(response) {
            var output = response.getReturnValue();

            var state = response.getState();
            if(component.isValid() && state == "SUCCESS" && output.isSuccess){
                var toastEvent = $A.get("e.force:showToast");
                    "title": "Success!",
                    "message": "AWB Details updated to Case Successfully!"
            } else if (state == "ERROR" || !output.isSuccess) {
                var errors = response.getError();
                if (errors[0] && errors[0].message) {
                    // Did not catch on the Server Side
                    component.set("v.message", errors[0].message);
                    component.set("v.messageError", true);
                } else if ( !output.isSuccess ) {
                    // Did catch on the Server Side
                    component.set("v.message", output.message);
                    component.set("v.messageError", true);

  • Thanks for the response. I have tried it in the callback too and it is working there, but trying to understand why it fails when invoked directly. Aug 21 '17 at 1:49
  • Why do you want to close the quick action if your are not invoking any button events after the page loads completely. If you want to still close the quickaction then you can use registerEvent and there is some attribute "afterLoaded" attribute associated with it. Not sure of the correct attribute name . please check once.
    – AjaySFDC
    Aug 22 '17 at 2:51

Use below in renderer file in aura omponent

afterRender  : function(cmp, helper) {
    var ret = this.superAfterRender ();
    // do custom rendering here

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.