Lightning – Displaying Toast or Custom Error Message in Quick Action

Currently, I'm working on lightning migration & i have a custom javascript button named convert.
This button will display multiple toast messages based on record criteria. Everything working as expected.

Suppose if the user is clicking the button it will open quick action as well as toast message.
The user will feel duplicate actions because he needs to close both toast and blank quick action. So, i have added below functionality

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

But the problem is now I'm able to see opening & closing the quick action view. Is there any better way to handle like displaying the message within quick action or closing the quick action in a better manner

My Component

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global"  controller="JavaScript_migration_controller">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
 <lightning:navigation aura:id="navigation"/>

Controller

({
    doInit : function(component, event, helper) {
        var action = component.get("c.fieldCheker");
        var recordId=component.get("v.recordId");
        action.setParams({
            "recId" : recordId
        });
        action.setCallback(this, function(response){
            var state = response.getState(); 
            if(state == 'SUCCESS') {                
                var returnValue= response.getReturnValue() 
                if(returnValue!=null){
                    if(returnValue.Promo__c==null || returnValue.Promo__c =='undefined'){
                        var toastEvent = $A.get("e.force:showToast");
                        toastEvent.setParams({
                            title: "Error!",
                            message: "To convert this lead, Please specify whether Marketing Promo is applied or not.\n\nYou can update this information using the 'Promo' field under 'Marketing Information' section.\n\nThank you for your co-operation.",
                            type: "Error"});
                        $A.get("e.force:closeQuickAction").fire()
                        $A.get("e.force:refreshView").fire();
                        toastEvent.fire(); 
                    }
                    else if(returnValue.Flag_Type__c == 'Related'){
                        alert("You don't have sufficient access to convert a related lead.\n\nPlease swap this lead to master by clicking the swap to master button\n\nFor more information contact SMO team.") 
                    }
                        else{
                            var navLink = component.find("navigation");
                            var pageRef = {
                                type: 'standard__recordPage',
                                attributes: {
                                    actionName: 'edit',
                                    objectApiName: 'Lead',
                                    recordId : recordId  
                                },
                            };
                            navLink.navigate(pageRef, true);
                        }
                }
            }
        });
        if(recordId !=null && 'undefined' ){
            $A.enqueueAction(action);
        }
        
    }
})
</aura:component>

Please guide me where i lost

Best Answer

You cannot remove the opening of the model, it will be there. I would suggest to show messages in the quick action model instead of a toast using slds alert.

https://www.lightningdesignsystem.com/components/alert/

That way users can see multiple messages, they wouldn't need to close 2 things.

Related Topic