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
Tim CaljeTim Calje 

How to create a lightning action without a modal popup?

Hi all,

I'm trying to create a new Lightning Action that only needs to trigger some server-side code, without any user-interaction.
Is there a way to do this without the default modal pop-up?

Thanks!
Alain CabonAlain Cabon
You can close the modal pop-up of a quick action into the function used by the callback (workaround) just after the call to some server-side code.

action.setCallback(this, function(response) {
   ...
   var wasDismissed = $A.get("e.force:closeQuickAction");
   wasDismissed.fire();
    ...
}

Component:
<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>
Controller JS:
({
    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);   
    }
})

Class Apex:
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];
    }
}

Regards