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
PieterSalesforcePieterSalesforce 

toast messages fires twice

I have a simple lightining component with following code
Component:
aura:component controller="CheckVATService" implements="force:hasRecordId,force:lightningQuickActionWithoutHeader">
	<aura:attribute name="account" type="Object"/>
    <aura:attribute name="simpleAccount" type="Object"/>
    <aura:attribute name="accountError" type="String"/>
    	
	<force:recordData aura:id="accountRecordLoader"
        recordId="{!v.recordId}"
        fields="VAT_Number__c"
        targetRecord="{!v.account}"
        targetFields="{!v.simpleAccount}"
        targetError="{!v.accountError}"
    />
	<aura:handler name="render" value="{!this}" action="{!c.handleClick}"/>
</aura:component>
Controller .js
({
	handleClick : function(component, event, helper) 
	{
		if (component.get("v.simpleAccount.VAT_Number__c") == null)
		{
			$A.get("e.force:closeQuickAction").fire();
			var resultsToast = $A.get("e.force:showToast");
			resultsToast.setParams({
        	   "title": "VAT Number",
        	   "message": "VAT Number is empty!",
        	   "type": "error",
        	   "key": "error"
			});
			resultsToast.fire();
		}else{
			var action = component.get("c.CallCheckVATService");
			action.setParams(
				{
			        VATNumber: component.get("v.simpleAccount.VAT_Number__c")
				}
			);
		
		    action.setCallback(this, function(a) 
		    {
		        if (a.getState() === "SUCCESS") 
		        {
		           if (a.getReturnValue())
		           {
		        	   $A.get("e.force:closeQuickAction").fire();
			           var resultsToast = $A.get("e.force:showToast");
			           resultsToast.setParams({
			        	   "title": "VAT Number",
			        	   "message": "VAT Number is valid",
			        	   "type": "success",
			        	   "key": "success"
			           });
			           resultsToast.fire();
			       }else{
			    	   $A.get("e.force:closeQuickAction").fire();
			           var resultsToast = $A.get("e.force:showToast");
			           resultsToast.setParams({
			        	   "title": "VAT Number",
			        	   "message": "VAT Number is invalid",
			        	   "type": "error",
			        	   "key": "error"
			           });
			           resultsToast.fire();
			       }
			        
		        } else if (a.getState() === "ERROR") {
		            $A.log("Errors", a.getError());
		        }
		    });
		    $A.enqueueAction(action);
	    }	    
	    
    
	}
})

When I have a value in VAT Number field, the logic is fine, it only shows once a toast message (whether it is valid or not).

But when I added the logic to check for empty VAT Number the toast fires twice.
Any ideas why?

brahmaji tammanabrahmaji tammana
Do you mean 'VAT Number is empty!' is firing twice ?
PieterSalesforcePieterSalesforce
Yes!