1

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

2
  • Can you show the messages in the quick action model instead of a toast? That way users can see multiple messages, they wouldn't need to close 2 things.
    – manjit5190
    Commented Jul 20, 2020 at 12:32
  • Could you please share your inputs as an answer
    – Pavan tej
    Commented Jul 20, 2020 at 12:44

2 Answers 2

1

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.

2
  • Hey, alert contains SVG tags.i'm not able to access. Could you please help
    – Pavan tej
    Commented Jul 20, 2020 at 16:50
  • It's possible now. See my answer below. And docs here: help.salesforce.com/s/… Commented Mar 16, 2022 at 9:23
1

I was able to achieve a Quick Action without a modal and a Toast using a LWC with a "headless action" with Summer '21's update. Only works on a record page. See https://help.salesforce.com/s/articleView?id=release-notes.rn_lwc_quick_actions.htm&type=5&release=232

js

import { LightningElement, api } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';

    export default class SampleToastNoModalQuickAction extends LightningElement {
        @api recordId;
        @api invoke() {
           this.showToast();
        }
        // displays the record Id in the toast
        showToast() {
            const event = new ShowToastEvent({
              title: "Notice",
              message: "Testing " + this.recordId,
              messageData: "",
              variant: "warning",
              mode: "pester"
          });
          this.dispatchEvent(event);
        }
    }

js-meta.xml

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>52.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__RecordAction</target>
    </targets>
     <targetConfigs>
    <targetConfig targets="lightning__RecordAction">
      <actionType>Action</actionType>
    </targetConfig>
  </targetConfigs>
</LightningComponentBundle>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .