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
Steve BerleySteve Berley 

quick actions - preventing or closing dialog

I'm creating a custom quick action for the lightning ui that requires no user input - just click the button and it starts.

Is it possible to prevent the Quick Action dialog from showing?  

While not as good a solution, I'd like to make it vanish immediately, but I can't make it happen.

Component:
<aura:component implements="force:lightningQuickActionWithoutHeader">
    <aura:handler name="init" value="{!this}" action="{!c.dismissIt}" />
</aura:component>

JS Controller:
dismissIt : function(component, event, helper) {
        var wasDismissed = $A.get("e.force:closeQuickAction").fire(); 
    }
As you can see they're as simple as possible but it's just not working.

Any suggestions?  

Thanks,

Steve 
 
NagendraNagendra (Salesforce Developers) 
Hi Steve,

May I suggest you please check with below link from the stack exchange community which might help you to accelerate further. Please let us know if this helps.

Thanks,
Nagendra
Alain CabonAlain Cabon
Hi,

I made some tests with the Winter 18 version but that doesn't work without opening a new popup.

I had already closed the Quick Action dialog in the past as soon as another popup was opened (navigation/using the data services) but the simple toast is not enough. I am trying to find my old test which works but that was not completely reliable nevertheless. 

Failed tests: all the renderer events are done before the display of the popup itself.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_renderers.htm

The button "Close" works but that is just the default sample of Salesforce for the test of the function handleClose .
<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId,force:appHostable,force:hasSObjectName">
    <aura:handler name="init" value="{!this}" action="{!c.dismissIt}" />
    <aura:method name="closeQuickAction" action="{!c.handleClose}" />
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="sObjectName" type="String" />
    ===> recordId:{!v.recordId}<br/>
    ===> sObjectName:{!v.sObjectName}
    <lightning:button label="Close" onclick="{!c.handleClose}"/>
</aura:component>
 
({
    dismissIt : function(component, event, helper) {   
        component.closeQuickAction();       
    },
    handleClose : function(cmp, event) { 
        alert('handleClose');
        var resultsToast = $A.get("e.force:showToast");
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            "title": "Success!",
            "message": "Try to close the window."
        });
        toastEvent.fire();
       
        var wasDismissed = $A.get("e.force:closeQuickAction");
        wasDismissed.fire();       
    },
    afterRender: function (component, helper) {
        this.superAfterRender();
        // interact with the DOM here
        alert('after render');
    },
    unrender: function () {
        this.superUnrender();
        // do custom unrendering here
        alert('component destroyed');
    }
})


User-added image

User-added image

User-added image

User-added image

Best regards
Alain
Steve BerleySteve Berley
thanks @Alain - you gave me a bunch of ideas that let me design my way around the challenge!
Alain CabonAlain Cabon
Hi Steve,

Here is the only sample I can give you which seems to work but I have to use ... a call back and a controller (useless normally):

It is a solution with only this call back that we need (the remote call should be useless).

action.setCallback(this, function(response) {
// here the force:closeQuickAction works (?) :
I tried that during my work but I am not sure it is 100% reliable.
​ }
 
<aura:component controller="ContactLEX" implements="force:lightningQuickActionWithoutHeader,force:hasRecordId,force:appHostable,force:hasSObjectName">
    <aura:handler name="init" value="{!this}" action="{!c.dismissIt}" />
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="sObjectName" type="String" />
    ===> recordId:<b>{!v.recordId}</b><br/>
    ===> sObjectName:<b>{!v.sObjectName}</b><br/> 
</aura:component>
 
({
    dismissIt : function(component, event, helper) {    
        
        var action = component.get("c.getContact");
        action.setParams({"contactId": component.get("v.recordId")});
      
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state === "SUCCESS") {
                var editRecordEvent = $A.get("e.force:editRecord");
                editRecordEvent.setParams({
                    "recordId": component.get("v.recordId")
                });
                editRecordEvent.fire();
                var wasDismissed = $A.get("e.force:closeQuickAction");
                wasDismissed.fire();
            } else {
                console.log('Problem getting contact, response state: ' + state);
            }
        });
        $A.enqueueAction(action);   
    }
})
 
public class ContactLEX {
@AuraEnabled
    public static Contact getContact(String contactId) {
        return [select firstname,lastname,accountid,account.name,level__c,phone,email from contact where id = :contactId];
    }
}

Best regards
Alain